Current code is designed to first fetch a limited set of artifact_ids that match the query (WHERE/ORDER BY from TQL) with limit/offset and then re-run the query with a 'COUNT' to get the total size of the dataset.
However it appears that the COUNT part (countArtifactsIdsMatchingQuery
) is consuming as much time as the initial search query (searchArtifactsIdsMatchingQuery
).
Relying on LIMIT/OFFSET is meant to limit the amount of data that transit from the DB to the application code. However, here we are dealing with artifact_ids only (integer) and even a large number of them should not be less efficient that re-running the count query.
The proposal is to replace the SQL slice and count by a PHP implementation.