Problem/Motivation
With Initially load all pages enabled, a non-AJAX request to ?page=N renders pages 0 through N in one response. This is intended, so deep links keep the previously loaded items. But it also means any visitor can make the view load its entire result set in a single request, simply by requesting the last page (or any higher page number).
On small views this is harmless. On views with thousands of results it can be very expensive, and since each page value is a separate URL, these requests usually aren't served from the page cache. Example with 2000 rows and 10 items per page (core 11.4.6, views_infinite_scroll 2.0.3):
?page=0: 10 rows, 21 KB, 0.54 s?page=100000: 2000 rows, 1.95 MB, 7.46 s
Right now the settings form doesn't mention this, so site builders may enable the option on large views without realising the impact.
Steps to reproduce
- Create a view with a large number of results that anonymous users can access, using the Infinite Scroll pager with Initially load all pages enabled.
- Visit the view with a high
?page=value, e.g.?page=100000. - All results are rendered in one response.
Proposed resolution
- Extend the description of Initially load all pages, for example:
"Important: When a page is requested directly (e.g.?page=50), all items up to and including that page are loaded and rendered in a single request. On views with many results this can lead to high memory usage and slow responses. Only enable this on views with a limited number of results, or set a maximum below." - Optional: add a setting Maximum number of pages to load initially (empty = unlimited, to keep the current behaviour) and cap the computed limit in
InfiniteScroll::query()accordingly. - Optional: treat page numbers beyond the last page like the default pager does, i.e. render no results instead of all of them.
Remaining tasks
- Agree on the wording of the description.
- Decide whether to add the maximum setting and/or the out-of-range handling.
- Patch / MR, plus tests if behaviour changes.
User interface changes
Updated description for Initially load all pages. Possibly a new Maximum number of pages to load initially field.
API changes
None.
Data model changes
Only if the maximum setting is added: a new pager option in the config schema.
Prepared with the help of AI
Issue fork views_infinite_scroll-3637993
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
anybodyPushed a fix to the issue fork.
While looking into this, I noticed that with Initially load all pages enabled, the pager ignores the Number of pages setting:
InfiniteScroll::query()overrides the limit set bySqlBase::query()without takingtotal_pagesinto account. So with Number of pages set to 2,?page=100still loaded all results.Changes:
InfiniteScrollTestto cover a page number beyond the last page, with and without Number of pages.Tests pass locally. Please review.
Comment #4
grevil commentedComment #6
grevil commented