Skip to content
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

Plugin queries extremely slow #148

Closed
chuckadams opened this issue Jan 29, 2025 — with Slack · 3 comments · Fixed by #151
Closed

Plugin queries extremely slow #148

chuckadams opened this issue Jan 29, 2025 — with Slack · 3 comments · Fixed by #151

Comments

Copy link
Contributor

This request can take >15s to respond:

http://api.aspirecloud.net/plugins/info/1.2/?action=query_plugins&request%5Bpage%5D=1&request%5Bper_page%5D=36&request%5Blocale%5D=en_US&request%5Bsearch%5D=security&request%5Bwp_version%5D=6.7

Doesn't appear to be any particular params, as this one took 21s to respond as well:

GET https://api.aspirecloud.net/plugins/info/1.2/?action=query_plugins&search=z

However, searching for 'a' returns quickly, so obviously an index isn't being used and we're doing a full table scan.

@chuckadams
Copy link
Contributor Author

In the 'duh' department:

    private static function applySearch(Builder $query, string $search): void
    {
        $query->where(function (Builder $q) use ($search) {
            $q->where('slug', 'like', "%{$search}%")
                ->orWhere('name', 'like', "%{$search}%")
                ->orWhere('short_description', 'like', "%{$search}%")
                ->orWhereFullText('description', $search);
        });
    }

Those first three are never going to use index. We need something like trigram indexes, and to rewrite the queries to use them.

@chuckadams
Copy link
Contributor Author

Other bad news for this primitive search implementation is that queries of multiple words like "gravity captcha" are not going to do the right thing, so we'll need to tokenize the search as independent terms. We should also just use fulltext on every column, which might tokenize the search for us anyway.

h/t to @namithj for the initial report and these followups.

@chuckadams
Copy link
Contributor Author

The main problem was that we weren't using indexes at all -- I simply forgot to add most of them when creating the tables! That's corrected in the above PR, but if we want <100ms searches in the future, we're going to need ElasticSearch or something like it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant