perf: paginate the subscribers admin list (closes #16)#42
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
Updates the Outpost admin “Subscribers” screen to avoid loading all subscriber rows at once by adding server-side pagination and a WordPress core pagination UI, addressing performance concerns raised in issue #16.
Changes:
- Add bounded subscriber queries using
LIMIT/OFFSETwith a fixed page size (50). - Compute a true total row count (
COUNT(*)) and use_n()for the count line. - Add
paginate_links()navigation while preserving the hashtag filter across pages.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+26
to
+35
| // Total count (respects the optional hashtag filter), used for the count | ||
| // line and to bound pagination. | ||
| if ( $hashtag_id ) { | ||
| $rows = $wpdb->get_results( $wpdb->prepare( | ||
| "SELECT s.*, h.hashtag FROM {$wpdb->prefix}outpost_subscribers s | ||
| JOIN {$wpdb->prefix}outpost_hashtags h ON h.id = s.hashtag_id | ||
| WHERE s.hashtag_id = %d ORDER BY s.created_at DESC", | ||
| $total = (int) $wpdb->get_var( $wpdb->prepare( | ||
| "SELECT COUNT(*) FROM {$sub_table} WHERE hashtag_id = %d", | ||
| $hashtag_id | ||
| ) ); | ||
| } else { | ||
| $rows = $wpdb->get_results( | ||
| "SELECT s.*, h.hashtag FROM {$wpdb->prefix}outpost_subscribers s | ||
| JOIN {$wpdb->prefix}outpost_hashtags h ON h.id = s.hashtag_id | ||
| ORDER BY s.created_at DESC" | ||
| ); | ||
| $total = (int) $wpdb->get_var( "SELECT COUNT(*) FROM {$sub_table}" ); | ||
| } |
| } | ||
|
|
||
| $total_pages = (int) max( 1, ceil( $total / $per_page ) ); | ||
| $paged = max( 1, isset( $_GET['paged'] ) ? (int) $_GET['paged'] : 1 ); |
b14016e to
b28009e
Compare
Replace the unbounded query with LIMIT/OFFSET pagination (50/page) plus an accessible paginate_links() nav. The count line reflects the true total via COUNT(*), the empty state keys off that total, and the page index is clamped so an out-of-range page never renders empty. The hashtag filter is preserved across pages. paginate_links() is echoed directly (not through wp_kses_post, which strips aria-current) per accessibility-lead review. Local vars are prefixed to avoid clobbering the $paged/$per_page WordPress globals. Co-Authored-By: Claude Opus 4.8 <[email protected]>
b28009e to
f605df7
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Phase 4. Closes #16.
What
The Subscribers screen loaded every row in one unbounded query. Now it paginates at 50/page with
LIMIT/OFFSETand a corepaginate_links()nav.COUNT(*)total (and_n()for singular/plural).$pagedis clamped so out-of-range pages never render empty.paged).Accessibility
accessibility-leadreviewed. Key fix from that review:paginate_links()is echoed directly rather than throughwp_kses_post(), which would strip thearia-current="page"indicator (WCAG 4.1.2). Nav has a uniquearia-label="Subscribers pagination".Verify
With >50 subscribers: pages of 50, working Previous/Next, current page marked, filter preserved across pages, accurate total count.
Closes #16
🤖 Generated with Claude Code