escargot icon indicating copy to clipboard operation
escargot copied to clipboard

Optimization to map hits to AR objects in one query rather result.length queries.

Open jamster opened this issue 14 years ago • 1 comments

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.

jamster avatar Jan 28 '11 04:01 jamster

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.

pfeiffer avatar Feb 08 '11 01:02 pfeiffer