Skip to content

Commit

Permalink
Try new limit 1 handling
Browse files Browse the repository at this point in the history
  • Loading branch information
richardr1126 committed Dec 13, 2024
1 parent 396f8c0 commit 22bf392
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions web/algos/chrono_trending.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ def handler(cursor: Optional[str], limit: int) -> dict:
if not isinstance(limit, int):
limit = int(limit)

if limit == 1:
logger.info("Returning a single main post for limit 1")
return {
'cursor': CURSOR_EOF,
'feed': [{'post': Post.select().order_by(Post.indexed_at.desc(), Post.cid.desc()).first().uri}]
}

try:
# Define time thresholds
now = datetime.now(timezone.utc)
Expand Down Expand Up @@ -125,12 +132,6 @@ def build_cursor_condition(cursor_value: Optional[str]):
if trending_cids:
main_posts_query = main_posts_query.where(Post.cid.not_in(trending_cids))

if limit == 1:
main_posts_query = main_posts_query.limit(1)
return {
'cursor': CURSOR_EOF,
'feed': [{'post': main_posts_query[0].uri}]
}

main_posts = list(main_posts_query.limit(limit)) # Fetch up to 'limit' main posts
#logger.debug(f"Fetched {len(main_posts)} main posts excluding trending posts")
Expand Down

0 comments on commit 22bf392

Please sign in to comment.