Closed vishalgspaceo closed 2 years ago
Hi @vishalgspaceo, Thank you for reporting this issue. It is prioritized in our roadmap, I'll notify you when the patch is ready.
Hi @vishalgspaceo,
I carefully examined the issue reproduction steps you provided. Actually this behaviour caused by an intended memory optimization. To avoid running out of device memory during the aggressive hits scrolling, the pagination engine keeps in memory 3 pages of hits before the first visible result and 3 pages of hits after last visible result. The value 3 is a hardcoded empirically derived value.
Let's examine the cases you reported one by one. First of all, these issues are not related to multi-index search. You can reproduce them in the single index search experience as well by setting the same parameters values.
Search result screen presenting 3 result hits at once (the case of multi-index demo).
Query.hitsPerPage = 1
means that 1 page of results is equivalent of 1 hit
HitsInteractor(infiniteScrolling(.on(withOffset: 10)))
means that the pagination engine might ensure the presence of 10 hits before the first visible hit and 10 hits after the latest visible hit and trigger the corresponding network request if needed.
pageCleanUpOffset = 3
means that the pagination engine when the page with index n
is loaded, removes the pages with indices less than n-3
and more than n+3
.
hitsPerPage
parameter is set to 1, it will perform 10 more network requests to fetch pages/hits at indices 3...12 (by the way, each of them counts as a separate search operation).4
. Since pageCleanUpOffset
is equal to 3, the pagination engine will purge the pages with indices less than 4-3 = 1 and 4+3 = 7. As result, the page/hit 0 will be purged. But the hit 0 is visible right now, so it will be requested again. hitsPerPage
value.Query.hitsPerPage = 10
HitsInteractor.infiniteScrolling(.on(withOffset: 40)
pageCleanUpOffset = 3
2
appears it asks the pagination engine to ensure the presence of hits with indices 3...42. hitsPerPage
is set to 10, it will require 4 additional network requests to fetch 4 pages of 10 hits (10+10+10+ one more page of 10 from which the pagination engine only requires first 3 hits). pageCleanUpOffset = 3
, the pagination engine will purge the pages with indices less than 4 - 3 = 1 and 4 + 3 = 7. So the first page with index 0 will be removed. But this is the first page which appears on the screen right now, so the pagination engine will request page at index 0 again and once it's fetched, will cleanup the page 4
. One more inifinite loop.Since from the InstantSearch side we cannot control or predict the number of visible hits due to different rows/cell sizes or even dynamic autolayout sizing, we decided to keep the pagination parameters configurable. The default configuration:
is reasonable for most mobile search experiences to ensure a decent performance. You can fine tune these parameters to ensure the best performance in your application. The fact that they are exposed doesn't mean that everything might work flawlessly with any set of values of these parameters. Briefly:
hitsPerPage
value less than the number of hits appearing on the screen. You might want to present at least one page of hits on you screen at once.hitsPerPage
value. The reason of this parameter is to request 1 more page before/after the visible area to ensure the smooth infinite scrolling. We expect that if a developer alters the default values of these parameters, he knows what he is doing.
The only problem I see here is the private and hardcoded pageCleanUpOffset
parameter and the missing warning in the documentation to be careful with pagination parameters 🙂
If you have a concrete infinite scrolling/pagination issue with your implementation where such specific pagination parameters make sense, I would be glad to discuss it and to find an optimal solution.
Describe the bug 🐛 I downloaded https://github.com/algolia/instantsearch-ios-examples this repo. I am using algolia in my project and found lots of calls happens . and found out that Multi Index search has pagination issue .
hitsPerPage
is not working properly. I used flex to check network history for api calls. https://github.com/FLEXTool/FLEX.To Reproduce 🔍 Steps to reproduce the behavior: I tried two cases here
MultiIndexDemoViewController.swift
MultiIndexDemoViewController.swift
Expected behavior 💭 Found that It reaches to infinite api calles , I checked in flex which has more than 12000+ api calls . If I scroll the collection view in demo InstantSearch -> Paging(Section) -> Paging Multiple Index. It would have crash too
Screenshots 🖥
https://drive.google.com/file/d/1eMKJ46lVlm4DisonZWp2gxMBS0ioOb1I/view?usp=sharing
Environment:
Additional context Let me know if you need more help here