Optimization to map hits to AR objects in one query rather result.length queries.#9
Optimization to map hits to AR objects in one query rather result.length queries.#9jamster wants to merge 2 commits intoangelf:masterfrom jamster:master
Conversation
|
Cool! This commit will raise an exception if ElasticSearch returned an ID that was deleted in the meantime, and doesn't fit well with the multi-model search. I dont find the :quick_search-option is the right way to go - but I agree that the performance hit on fetching each and every object is not worth it. What I've implemented in my projects using Escargot is a layer between my application and Escargot. I only fetch the IDs via Escargot, and make sure only to fetch AR-models on the records I actually need in my application - eg. after paging/slicing has been done. This also allows options to the finder, eg. :include => [:image] to reduce N+1 queries. Preferably something like this would be implemented in Escargot, as the current implementation isn't very optimized. |
This optimization sets the query to pull ids only (:ids_only option in Rubberband) and then compacts the array and passes that into the find method. This makes for a single query rather than having one query for each hit returned. It also compacts and uniqifies the array.