Skip to content

Conversation

@Digvijay-x1
Copy link
Contributor

Proposal to optimize the expensive search query issue #10777 .

Previously, XpathEngine executed the search query immediately by calling .pluck(:id), which loaded all matching record IDs into memory as an Array. For broad searches (ex 300,000+ matches), this could cause memory spikes and blocked the worker, even if the user only requested the first 10 results.

Changing XpathEngine to return an ActiveRecord::Relation instead of an Array. This allows the SearchController to apply pagination (LIMIT and OFFSET) directly to the SQL query before execution .

Also using .count to avoid unnecessary loading of queries by .size.

So at the end we are trading 1 massive, memory-intensive query for 2 small, efficient queries.

Before:

Query1 : Load everything from the db at once .

After:

Query1 : Count the total matching result and give only the number .
Query2 : Fetch only the results the end user can see at the moment .

@github-actions github-actions bot added the Frontend Things related to the OBS RoR app label Dec 10, 2025
@Digvijay-x1 Digvijay-x1 marked this pull request as ready for review December 15, 2025 20:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Frontend Things related to the OBS RoR app

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant