-
-
Notifications
You must be signed in to change notification settings - Fork 861
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Global Search performance #2519
Comments
@isecchin I guess it's intentional since we just basically loop on each related column. However, I do agree on your suggestion to group related columns to a single query. I would gladly accept a PR for this one. Thanks 🍻 |
Ok, great ! |
Summary of problem or feature request
Hi all, I've been using this package for a few months now and it's been working great for my requirements !
This weekend though, during some patches to boost the performance of my app, I've noticed that a few queries were taking a bit longer than I expected, and I think I managed to find what was causing it.
I'm not sure if this is intentional or not, but when looking through the source code of the package, I saw that on the
globalSearch()
method, we don't call theresolveRelationColumn()
like we do on the column search and ordering.The result of this is that it adds a subquery for each column of a relationship that is available on the global search instead of performing the join. On a table with just a few thousands of records, the SQL ran 3x slower than it did with the join.
Code snippet of problem
Say that you have an instance of the DataTables for a User model that has a relation to an "Employee" model, which stores all the basic information, such as first and last names, address, etc.
Now you want to allow the user to perform the global search with any of the parameters of the
Employee
relationship, this will add a subquery for each attribute, for example:If we add the line
Right before the following one:
laravel-datatables/src/QueryDataTable.php
Line 751 in 7e45885
We get a much nicer and faster query (with a single sub-query per relationship):
So my question here is: is this intentional and we can't do this for the globalSearch or is it just something that went unnoticed?
I'm glad to open a PR with the patch if needed.
System details
The text was updated successfully, but these errors were encountered: