feat: v2.21.0 paging for homepage, likes and admin dashboard
The homepage showed only the 20 newest notes and /likes the 50 newest, with no way back. The admin dashboard paged list_notes()'s default 50 newest, so it always said 'Page 1 of 2'. All three now count with count_notes() and fetch one page with limit/offset. Public pages get '<- Newer / Page N of M / Older ->' with rel=prev/next (h-feed paging), ?page=1 redirects to the bare URL, bad pages 404; the dashboard falls back to the nearest valid page. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
9074c9a08c
commit
615354d17e
11 files changed
+373
-60
No files matched your search
+26
-12
@@ -519,6 +519,30 @@ def get_note(
|
||||
return note
|
||||
|
||||
|
||||
def _list_filters(published_only: bool, likes: Optional[bool]) -> tuple[str, list]:
|
||||
"""WHERE clause shared by list_notes() and count_notes()"""
|
||||
where = "deleted_at IS NULL"
|
||||
if published_only:
|
||||
where += " AND published = 1"
|
||||
# likes: None = all notes, False = leave likes out, True = only likes (v2.5.0)
|
||||
if likes is True:
|
||||
where += " AND like_of IS NOT NULL"
|
||||
elif likes is False:
|
||||
where += " AND like_of IS NULL"
|
||||
return where, []
|
||||
|
||||
|
||||
def count_notes(published_only: bool = False, likes: Optional[bool] = None) -> int:
|
||||
"""
|
||||
Number of notes list_notes() would return with no limit (v2.21.0)
|
||||
|
||||
Same filters as list_notes(); used to work out page counts.
|
||||
"""
|
||||
where, params = _list_filters(published_only, likes)
|
||||
db = get_db(current_app)
|
||||
return db.execute(f"SELECT COUNT(*) FROM notes WHERE {where}", params).fetchone()[0]
|
||||
|
||||
|
||||
def list_notes(
|
||||
published_only: bool = False,
|
||||
limit: int = 50,
|
||||
@@ -611,18 +635,8 @@ def list_notes(
|
||||
raise ValueError("Offset must be >= 0")
|
||||
|
||||
# 2. BUILD QUERY
|
||||
# Start with base query
|
||||
query = "SELECT * FROM notes WHERE deleted_at IS NULL"
|
||||
|
||||
# Add filters
|
||||
params = []
|
||||
if published_only:
|
||||
query += " AND published = 1"
|
||||
# likes: None = all notes, False = leave likes out, True = only likes (v2.5.0)
|
||||
if likes is True:
|
||||
query += " AND like_of IS NOT NULL"
|
||||
elif likes is False:
|
||||
query += " AND like_of IS NULL"
|
||||
where, params = _list_filters(published_only, likes)
|
||||
query = f"SELECT * FROM notes WHERE {where}"
|
||||
|
||||
# Add ordering (safe because order_by validated above)
|
||||
query += f" ORDER BY {order_by} {order_dir}"
|
||||
|
||||
Reference in new issue
Block a user