From 2f801dd9f5dc75827ad1bca43e2e309d79b0e74e Mon Sep 17 00:00:00 2001 From: Gandalf <gandalf@hive.io> Date: Sat, 9 May 2020 18:45:16 -0400 Subject: [PATCH] [JES] Whoopsie. Messed up pagination on empty tags. Also fix bad id request --- hive/server/bridge_api/methods.py | 42 +++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/hive/server/bridge_api/methods.py b/hive/server/bridge_api/methods.py index 4e294ccee..a89166156 100644 --- a/hive/server/bridge_api/methods.py +++ b/hive/server/bridge_api/methods.py @@ -206,31 +206,57 @@ async def get_ranked_posts(context, sort, start_author='', start_permlink='', elif tag[:5] == 'hive-': if start_author and start_permlink: if sort == 'trending': - sql = sql % """ AND hive_posts_cache.community_id = (SELECT community_id FROM communities WHERE name = :community_name ) + sql = sql % """ AND hive_posts_cache.community_id = (SELECT hive_communities.id FROM hive_communities WHERE name = :community_name ) AND hive_posts_cache.sc_trend <= (SELECT sc_trend FROM hive_posts_cache WHERE permlink = :permlink AND author = :author) AND hive_posts_cache.post_id != (SELECT post_id FROM hive_posts_cache WHERE permlink = :permlink AND author = :author) """ elif sort == 'hot': - sql = sql % """ AND hive_posts_cache.community_id = (SELECT community_id FROM communities WHERE name = :community_name ) + sql = sql % """ AND hive_posts_cache.community_id = (SELECT hive_communities.id FROM hive_communities WHERE name = :community_name ) AND hive_posts_cache.sc_hot <= (SELECT sc_hot FROM hive_posts_cache WHERE permlink = :permlink AND author = :author) AND hive_posts_cache.post_id != (SELECT post_id FROM hive_posts_cache WHERE permlink = :permlink AND author = :author) """ elif sort == 'created': - sql = sql % """ AND hive_posts_cache.community_id = (SELECT community_id FROM communities WHERE name = :community_name ) + sql = sql % """ AND hive_posts_cache.community_id = (SELECT hive_communities.id FROM hive_communities WHERE name = :community_name ) AND hive_posts_cache.post_id < (SELECT post_id FROM hive_posts_cache WHERE permlink = :permlink AND author = :author) """ elif sort == 'promoted': - sql = sql % """ AND hive_posts_cache.community_id = (SELECT community_id FROM communities WHERE name = :community_name ) + sql = sql % """ AND hive_posts_cache.community_id = (SELECT hive_communities.id FROM hive_communities WHERE name = :community_name ) AND hive_posts_cache.promoted <= (SELECT promoted FROM hive_posts_cache WHERE permlink = :permlink AND author = :author) AND hive_posts_cache.post_id != (SELECT post_id FROM hive_posts_cache WHERE permlink = :permlink AND author = :author) """ else: - sql = sql % """ AND hive_posts_cache.community_id = (SELECT community_id FROM communities WHERE name = :community_name ) + sql = sql % """ AND hive_posts_cache.community_id = (SELECT hive_communities.id FROM hive_communities WHERE name = :community_name ) AND hive_posts_cache.payout <= (SELECT payout FROM hive_posts_cache WHERE permlink = :permlink AND author = :author) AND hive_posts_cache.post_id != (SELECT post_id FROM hive_posts_cache WHERE permlink = :permlink AND author = :author) """ else: sql = sql % """ AND hive_communities.name = :community_name """ else: - if sort in ['payout', 'payout_comments']: - sql = sql % """ AND hive_posts_cache.category = :tag""" + if start_author and start_permlink: + if sort == 'trending': + sql = sql % """ AND hive_posts_cache.category = :tag + AND hive_posts_cache.sc_trend <= (SELECT sc_trend FROM hive_posts_cache WHERE permlink = :permlink AND author = :author) + AND hive_posts_cache.post_id != (SELECT post_id FROM hive_posts_cache WHERE permlink = :permlink AND author = :author) + """ + elif sort == 'hot': + sql = sql % """ AND hive_posts_cache.category = :tag + AND hive_posts_cache.sc_hot <= (SELECT sc_hot FROM hive_posts_cache WHERE permlink = :permlink AND author = :author) + AND hive_posts_cache.post_id != (SELECT post_id FROM hive_posts_cache WHERE permlink = :permlink AND author = :author) + """ + elif sort == 'created': + sql = sql % """ AND hive_posts_cache.category = :tag + AND hive_posts_cache.post_id < (SELECT post_id FROM hive_posts_cache WHERE permlink = :permlink AND author = :author) + """ + elif sort == 'promoted': + sql = sql % """ AND hive_posts_cache.category = :tag + AND hive_posts_cache.promoted <= (SELECT promoted FROM hive_posts_cache WHERE permlink = :permlink AND author = :author) + AND hive_posts_cache.post_id != (SELECT post_id FROM hive_posts_cache WHERE permlink = :permlink AND author = :author) + """ + else: + sql = sql % """ AND hive_posts_cache.category = :tag + AND hive_posts_cache.payout <= (SELECT payout FROM hive_posts_cache WHERE permlink = :permlink AND author = :author) + AND hive_posts_cache.post_id != (SELECT post_id FROM hive_posts_cache WHERE permlink = :permlink AND author = :author) + """ else: - sql = sql % """ AND hive_posts_cache.post_id IN (SELECT post_id FROM hive_post_tags WHERE tag = :tag)""" + if sort in ['payout', 'payout_comments']: + sql = sql % """ AND hive_posts_cache.category = :tag""" + else: + sql = sql % """ AND hive_posts_cache.post_id IN (SELECT post_id FROM hive_post_tags WHERE tag = :tag)""" sql_result = await db.query_all(sql, author=start_author, limit=limit, tag=tag, permlink=start_permlink, community_name=tag) posts = [] -- GitLab