Skip to content

Feature(template-gallery): add server-side pagination - #80

Open
Musicminion wants to merge 3 commits into
server-profrom
feat-template-gallery-pagination
Open

Feature(template-gallery): add server-side pagination#80
Musicminion wants to merge 3 commits into
server-profrom
feat-template-gallery-pagination

Conversation

@Musicminion

@Musicminion Musicminion commented Aug 26, 2026

Copy link
Copy Markdown
Member
  • 9 templates per page, fetched page by page instead of loading the whole list
  • backend: /api/templates takes page/pageSize/q (search), sorts and paginates in mongo
  • frontend: port the upstream gallery pagination bar, move search onto its own row, center the category header, right-align the sort buttons

Description

截屏2026-08-26 18 06 20

Related issues / Pull Requests

Docs

Upgrading to Ayakaleaf Pro 6.3: Template Gallery indexes (optional)

The gallery now pages, sorts and searches in MongoDB. It works without any preparation; with thousands of templates, add these indexes to keep it fast (safe to re-run, mongo/sharelatex = your container and database names):

docker exec mongo mongosh sharelatex --quiet --eval '
db.templates.createIndex({category:1,lastUpdated:-1},{name:"category_1_lastUpdated_-1",background:true});
db.templates.createIndex({lastUpdated:-1},{name:"lastUpdated_-1",background:true});
db.templates.createIndex({category:1,name:1},{name:"category_1_name_1_ci",collation:{locale:"en",strength:2},background:true});
db.templates.createIndex({name:1},{name:"name_1_ci",collation:{locale:"en",strength:2},background:true});
'

Keep the collation on the two *_ci indexes as written — the gallery
queries with the same collation and MongoDB only uses a matching index.

Contributor Agreement

- 9 templates per page, fetched page by page instead of loading the whole list
- backend: /api/templates takes page/pageSize/q (search), sorts and paginates in mongo
- frontend: port the upstream gallery pagination bar, move search onto its own row, center the category header, right-align the sort buttons

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1c7940961d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines 76 to 78
.then(data => {
setLoadedTemplates(data.templates)
setVisibleTemplates(data.templates)
setTotalTemplatesCount(data.totalSize)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Ignore responses from superseded gallery requests

When page, sort, or debounced search parameters change before an earlier request finishes, every response still updates the same state. A slower obsolete request can therefore overwrite the latest response, leaving (for example) page 2's templates displayed while the pagination marks page 3 as current. Track the latest request or abort superseded requests before applying their results.

Useful? React with 👍 / 👎.

Comment on lines +181 to +184
// Must match the collation of the name indexes described in UPGRADE-6.3.md
// (created by the operator, see the upgrade notes), otherwise mongo falls
// back to an in-memory sort.
const NAME_COLLATION = { locale: 'en', strength: 2 }

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Add the indexes referenced by the paginated query

The referenced UPGRADE-6.3.md does not exist anywhere in the repository, and the TemplateSchema defines no corresponding indexes. Consequently, both { lastUpdated, _id } and collation-aware { name, _id } sorts remain blocking sorts over the complete matching collection before skip and limit are applied, undermining server-side pagination and potentially spilling or failing on large galleries. Ship explicit operator upgrade instructions or migrations for the required compound indexes.

Useful? React with 👍 / 👎.

Comment on lines +48 to +51
aria-label={t('go_to_first_page')}
onClick={() => onPageChange(1)}
>
<span aria-hidden="true">&lt;&lt;</span> First

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Translate the visible pagination labels

For every non-English locale, the new controls still visibly render the English words First, Prev, Next, and Last; only their screen-reader labels use translations. This regresses the localized gallery UI, so the visible labels should also use the existing i18n keys.

Useful? React with 👍 / 👎.

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.

1 participant