Comments (5)
Hi @Menelle how are you?!
I've tried to reproduce your issue but I was not able to, in the meilisearch-rails you can find a playground that uses Kaminari and another model with pagy already configured.
Can you try to reproduce it using them?
Also, the pagy is only affected by the items: 24
not by the limit: ...
during the pagy_search
source
from meilisearch-rails.
Hello @brunoocasali
The limit and eager loading seems to work. The benchmark/tap we used to monitor memory and perf played the query prior to pagy, resulting in the full index being fetched... So that's on us.
However, that was not the cause of the performance issue, it just not helped the debugging.
We removed our Frankfurt index from meilisearch and recreated it in San-Francisco.
Our web servers are hosted in Oregon.
Doing that, we observed a X10 in perf, from 650ms to 70ms.
from meilisearch-rails.
Hello @brunoocasali, thank you for your message.
It seems that the issue occurs prior to the pagination (pagy_meilisearch
call inside the controller)
In our tests, the pagy_search
call is actually returning the full index. this is the line?
We observe a different response from meili when we eager load associations. I think that's what's causing our issue as with the includes
, the limit
seems ignored.
without associations:
# controller
q = Product.pagy_search(params[:q], **options)
puts "------------------- RESPONSE #{q.inspect} ---------------------"
=> [Product(id: integer, brand_id: integer, ...), nil, {:filter=>["type=AppProduct AND release_at_timestamp<=1693958400"], :limit=>240, :sort=>["release_at_timestamp:desc"]}]
with associations loaded with includes
:
# model
ActiveRecord_Relation.include Pagy::Meilisearch
# controller
q = Product.includes(:category_secondary, :gender, :brand).pagy_search(params[:q], **options)
puts "------------------- RESPONSE #{q.inspect} ---------------------"
=> [#<ActiveRecord::Relation [#<AppProduct id: 230, brand_id: 1, ...]>, nil, {:filter=>["type=AppProduct AND release_at_timestamp<=1693958400"], :limit=>240, :sort=>["release_at_timestamp:desc"]}]
puts "------------------- ITEMS RETURNED #{q.first.size} ---------------------"
=> "------------------- ITEMS RETURNED 6102 ---------------------"
# here Full index is returned, +6000 items, causing the bloat
Is this the expected behavior? We were expecting almost an instant response from this call as it is basically just building an array waiting to be executed by the next line. But the Self
is executing the query which, at this point, has no conditions thus returns the whole table.
When we run the query using the ms_search
method, we've got 240 items returned as expected (arg :limit
)
q = Product.includes(:category_secondary, :gender, :brand).ms_search(params[:q], **options)
puts "------------------- PAGY SEARCH RESULTS #{q.inspect} ---------------------"
=> ------------------- PAGY SEARCH RESULTS [#<AppProduct id: 1886, brand_id: 2, ...] ---------------------
puts "------------------- PAGY SEARCH RESULTS #{q.size} ---------------------"
=> ------------------- PAGY SEARCH RESULTS 240---------------------
From what we see in the codebase, the pagy_search
method should behave like ms_search
, and accept the limit arg.
Just to be sure, we tried to call pagy_search
with items: ...
in place of limit: ...
, and it raised MeiliSearch::ApiError (400 Bad Request - Unknown field `items`: expected one of `q`, `offset`, `limit`, `page`, `hitsPerPage`, `attributesToRetrieve`, `attributesToCrop`, `cropLength`, `attributesToHighlight`, `showMatchesPosition`, `filter`, `sort`, `facets`, `highlightPreTag`, `highlightPostTag`, `cropMarker`, `matchingStrategy
as expected.
I hope your message was understood correctly. Let me know if we can provide more info. I will look at the playground you mentioned. Thank you.
from meilisearch-rails.
Hi @Menelle thanks for your answer!
I'm still trying to understand what is happening but I suppose you controller should look like this:
def index
product_filters = ["type=AppProduct AND release_at_timestamp<=#{Date.current.strftime('%s')}"]
options = { filter: product_filters }.tap { |options|
options[:sort] = ["release_at_timestamp:desc"] if params[:q].to_s.blank?
}
hits = Product.includes(:category_secondary, :gender, :brand).pagy_search(params[:q], **options)
@pagy, @products = pagy_meilisearch(hits, items: 240)
end
With no limit
at all... Pagy uses the exhaustive pagination from Meilisearch behind the scenes.
If it does not work by doing that, I would suggest removing the includes
and then adding the relationships again, one by one.
I'm eager to hear your feedback.
from meilisearch-rails.
Amazing to know that! So I guess this issue can be closed right?! Let me know if this is a mistake! :)
Thanks for using Meilisearch!
from meilisearch-rails.
Related Issues (20)
- Index not created since 0.11.0 - 404 Not Found HOT 8
- Upgrading to 0.11.0 produces "The request was not processed in the expected time." repeatedly. HOT 1
- Split and decouple models in integration_spec.rb to their separate files
- Improve test robustness and confidence with end-to-end system tests
- Improve spec style clarity
- Add unit tests for individual methods
- Support and test Sequel properly
- Document multi_search interface in README HOT 1
- single index sharing didnt create new index. HOT 3
- Using attribute option with custom primary key will break fetching
- Polymorphic shared indexes HOT 3
- Index-first search HOT 1
- Rename root module to `Meilisearch` instead of `MeiliSearch`
- Refactor `meilisearch.rb`
- Global `ms_without_auto_index` in `Meilisearch`
- MeiliSearch::Rails::MSCleanUpJob 404 error when deleting records HOT 3
- Update Gem dependencies HOT 6
- Error: MeiliSearch::TimeoutError: The request was not processed in the expected time. HOT 29
- Race condition in proximity precision test
- Undefined method `after_destroy_commit' when using with Mongoid HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from meilisearch-rails.