forked from retoor/devplacepy
feat: replace per-author cap with interleaving to avoid dropping posts in feed and home
The old `diversify_by_author` capped each author to 2 posts per page, silently dropping excess rows. The new `interleave_by_author` reorders the full result set so no two consecutive posts share an author, preserving every post while breaking up same-author runs. `paginate_diverse` loses its `max_per_author` and `pool` parameters; the home route now fetches exactly 6 rows and interleaves them instead of over-fetching 50 and capping. Tests are rewritten to verify interleaving behavior and per-author chronological order preservation.
This commit is contained in:
+3
-3
@@ -31,7 +31,7 @@ from devplacepy.database import (
|
||||
get_news_images_by_uids,
|
||||
get_setting,
|
||||
get_int_setting,
|
||||
diversify_by_author,
|
||||
interleave_by_author,
|
||||
get_user_post_count,
|
||||
)
|
||||
from devplacepy.templating import templates
|
||||
@@ -506,9 +506,9 @@ async def landing(request: Request):
|
||||
if "posts" in db.tables:
|
||||
posts_table = get_table("posts")
|
||||
raw_posts = list(
|
||||
posts_table.find(deleted_at=None, order_by=["-created_at"], _limit=50)
|
||||
posts_table.find(deleted_at=None, order_by=["-created_at"], _limit=6)
|
||||
)
|
||||
raw_posts = diversify_by_author(raw_posts, max_per_author=2, limit=6)
|
||||
raw_posts = interleave_by_author(raw_posts)
|
||||
if raw_posts:
|
||||
post_uids = [p["uid"] for p in raw_posts]
|
||||
author_uids = [p["user_uid"] for p in raw_posts]
|
||||
|
||||
Reference in New Issue
Block a user