Skip to content

Commit

Permalink
Merge pull request #336 from steemit/optimize_get_ranked_post
Browse files Browse the repository at this point in the history
add timing log; add new where condition only get 7 days posts
  • Loading branch information
yuekun0707 authored Sep 24, 2024
2 parents 1d0d378 + 15b6cd4 commit f2d4cad
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions hive/server/bridge_api/cursor.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Cursor-based pagination queries, mostly supporting bridge_api."""

from datetime import datetime
from datetime import datetime, timedelta
from dateutil.relativedelta import relativedelta

# pylint: disable=too-many-lines
Expand Down Expand Up @@ -119,7 +119,17 @@ async def pids_by_community(db, ids, sort, seek_id, limit):
# setup
field, pending, toponly, gray, promoted = definitions[sort]
table = 'hive_posts_cache'
where = ["community_id IN :ids"] if ids else ["community_id IS NOT NULL AND community_id != 1337319"]
where = []
if ids:
if sort != 'created':
now = datetime.now()
seven_days_ago = now - timedelta(days=7)
timestamp = int(seven_days_ago.timestamp())
where.append(f"community_id IN :ids and created_at >= to_timestamp({timestamp})")
else:
where.append("community_id IN :ids")
else:
where.append("community_id IS NOT NULL AND community_id != 1337319")

# select
if gray: where.append("is_grayed = '1'")
Expand Down

0 comments on commit f2d4cad

Please sign in to comment.