Skip to content

Fix history page pagination off-by-one#12430

Merged
mekarpeles merged 2 commits into
internetarchive:masterfrom
lokesh:fix-pagination
Apr 22, 2026
Merged

Fix history page pagination off-by-one#12430
mekarpeles merged 2 commits into
internetarchive:masterfrom
lokesh:fix-pagination

Conversation

@lokesh

@lokesh lokesh commented Apr 22, 2026

Copy link
Copy Markdown
Collaborator

This fixes:

Technical

PR #12169 migrated pagination to the ol-pagination web component, which uses 1-indexed URLs (page 1 = no ?page param, page 2 = ?page=2).

The history handler was left on the old 0-indexed scheme (?page=0 = page 1, offset = 20 * page), and the template bridged them with a +1 - but applied it when passing the page to the component rather than when interpreting the URL. So each click drifted further out of sync.

How the bug plays out:
1 ) Initial load at ?m=history (no ?page)

  • Backend reads page=0 → offset=0 → shows revisions 1–20 ✓ (correct)
  • Template reads URL's page=0 → passes 0+1=1 to component
  • Component thinks it's on page 1 → "Next" link generated as ?page=2 ✓ (looks
    right)
  1. User clicks "Next", URL becomes ?page=2

The fix:
Align the handler, the URL, and the template on 1-indexed pages to match every other paginated page on the site (admin/people/edits, loan_history, admin/memory).

Also replaces the brittle len(h) == 20 has-next check with a limit + 1 fetch so the Next arrow no longer appears on exact-20-item last pages.

Testing

Visit a history page with more than 20 revisions and navigate forward and backwards with pagination.

Screenshot

Stakeholders

@cdrini

…etarchive#12420)

PR internetarchive#12169 migrated pagination to the ol-pagination web component, which
uses 1-indexed URLs (page 1 = no ?page param, page 2 = ?page=2). The
history handler was left on the old 0-indexed scheme (?page=0 = page 1,
offset = 20 * page), and the template bridged them with a `+1` — but
applied it when passing the page to the component rather than when
interpreting the URL. So each click drifted further out of sync.

Align the handler, the URL, and the template on 1-indexed pages to match
every other paginated page on the site (admin/people/edits, loan_history,
admin/memory). This fixes:

  - internetarchive#12398: Previous arrow on page 2 links back to page 2
  - internetarchive#12420: History pages double-skip, making most revisions unreachable

Also replaces the brittle `len(h) == 20` has-next check with a `limit + 1`
fetch so the Next arrow no longer appears on exact-20-item last pages.
@lokesh lokesh requested a review from RayBB April 22, 2026 02:25
@lokesh lokesh marked this pull request as ready for review April 22, 2026 02:33
@lokesh lokesh changed the title Fix history page pagination off-by-one (#12398, #12420) Fix history page pagination off-by-one Apr 22, 2026
@mekarpeles mekarpeles self-assigned this Apr 22, 2026
@mekarpeles mekarpeles merged commit 496e51f into internetarchive:master Apr 22, 2026
3 checks passed
Comment on lines +205 to +206
# Clamp so legacy ?page=0 links resolve to the first page instead of a negative offset.
offset = limit * max(0, safeint(i.page) - 1)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not fix the front end to maintain compatibility rather than making a breaking change to the backend?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ol-pagination component is already powering admin/people/edits, loan_history, and admin/memory, all of which have been 1-indexed all along. History was the lone 0-indexed holdout. So it didn't seem to make sense to add permanent complexity to the front-end component to preserve a convention only one page used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants