Skip to content

Use limited count queries also for scoped searches

Jan Provaznik requested to merge jprovazn-scoped-limit into master

MR for #40540 (closed) added limits for count queries for global searches. Because some queries may still time out if search is done on a big project (especially on gitlab-ce), it makes sense to use limits for scoped searches too.

For getting notes, complex query with multiple UNIONs (for each of noteable type) is constructed, then using LIMIT on such query is still slow because DB has to compute UNIONs w/o limit first - snippet https://gitlab.com/snippets/1701638 shows that just applying limit on the final query is not sufficient. For getting only limited count, we can break the UNION query into multiple smaller queries on which we can use LIMIT, also we don't have to search all noteable types if we reach the limit earlier.

This patch also improves single_commit_result? check.

Related to #43242 (closed) EE version of this patch: gitlab-ee!4782

Edited by Jan Provaznik

Merge request reports