Skip to content
Snippets Groups Projects
Commit 7a4e2b3e authored by Bartek Wrona's avatar Bartek Wrona
Browse files

Merge branch 'issue_37_wrong_trending_tags' into 'develop'

Issue 37 wrong trending tags

See merge request !82
parents ac30d805 c6bc799b
No related branches found
No related tags found
4 merge requests!456Release candidate v1 24,!230Setup monitoring with pghero,!135Enable postgres monitoring on CI server,!82Issue 37 wrong trending tags
...@@ -50,10 +50,10 @@ class Posts: ...@@ -50,10 +50,10 @@ class Posts:
else: else:
cls._miss += 1 cls._miss += 1
sql = """ sql = """
SELECT hp.id SELECT hp.id
FROM hive_posts hp FROM hive_posts hp
INNER JOIN hive_accounts ha_a ON ha_a.id = hp.author_id INNER JOIN hive_accounts ha_a ON ha_a.id = hp.author_id
INNER JOIN hive_permlink_data hpd_p ON hpd_p.id = hp.permlink_id INNER JOIN hive_permlink_data hpd_p ON hpd_p.id = hp.permlink_id
WHERE ha_a.name = :a AND hpd_p.permlink = :p WHERE ha_a.name = :a AND hpd_p.permlink = :p
""" """
_id = DB.query_one(sql, a=author, p=permlink) _id = DB.query_one(sql, a=author, p=permlink)
...@@ -130,16 +130,17 @@ class Posts: ...@@ -130,16 +130,17 @@ class Posts:
except Exception: except Exception:
pass pass
tags = [result['post_category']] if not result['depth']:
if md and 'tags' in md and isinstance(md['tags'], list): tags = [result['post_category']]
tags = tags + md['tags'] if md and 'tags' in md and isinstance(md['tags'], list):
tags = map(lambda tag: (str(tag) or '').strip('# ').lower()[:32], tags) tags = tags + md['tags']
tags = filter(None, tags) tags = map(lambda tag: (str(tag) or '').strip('# ').lower()[:32], tags)
from funcy.seqs import distinct tags = filter(None, tags)
tags = list(distinct(tags))[:5] from funcy.seqs import distinct
tags = list(distinct(tags))[:5]
for tag in tags: for tag in tags:
Tags.add_tag(result['id'], tag) Tags.add_tag(result['id'], tag)
if not DbState.is_initial_sync(): if not DbState.is_initial_sync():
if error: if error:
...@@ -165,7 +166,7 @@ class Posts: ...@@ -165,7 +166,7 @@ class Posts:
is_paidout = COALESCE( CAST( data_source.is_paidout as BOOLEAN ), ihp.is_paidout ) is_paidout = COALESCE( CAST( data_source.is_paidout as BOOLEAN ), ihp.is_paidout )
FROM FROM
( (
SELECT ha_a.id as author_id, hpd_p.id as permlink_id, SELECT ha_a.id as author_id, hpd_p.id as permlink_id,
t.total_payout_value, t.total_payout_value,
t.curator_payout_value, t.curator_payout_value,
t.author_rewards, t.author_rewards,
...@@ -320,17 +321,17 @@ class Posts: ...@@ -320,17 +321,17 @@ class Posts:
def update_child_count(cls, child_id, op='+'): def update_child_count(cls, child_id, op='+'):
""" Increase/decrease child count by 1 """ """ Increase/decrease child count by 1 """
sql = """ sql = """
UPDATE UPDATE
hive_posts hive_posts
SET SET
children = GREATEST(0, ( children = GREATEST(0, (
SELECT SELECT
CASE CASE
WHEN children is NULL THEN 0 WHEN children is NULL THEN 0
WHEN children=32762 THEN 0 WHEN children=32762 THEN 0
ELSE children ELSE children
END END
FROM FROM
hive_posts hive_posts
WHERE id = (SELECT parent_id FROM hive_posts WHERE id = :child_id) WHERE id = (SELECT parent_id FROM hive_posts WHERE id = :child_id)
)::int )::int
...@@ -365,7 +366,7 @@ class Posts: ...@@ -365,7 +366,7 @@ class Posts:
allow_curation_rewards = :allow_curation_rewards, allow_curation_rewards = :allow_curation_rewards,
beneficiaries = :beneficiaries beneficiaries = :beneficiaries
WHERE WHERE
hp.author_id = (SELECT id FROM hive_accounts WHERE name = :author) AND hp.author_id = (SELECT id FROM hive_accounts WHERE name = :author) AND
hp.permlink_id = (SELECT id FROM hive_permlink_data WHERE permlink = :permlink) hp.permlink_id = (SELECT id FROM hive_permlink_data WHERE permlink = :permlink)
""" """
DB.query(sql, author=op['author'], permlink=op['permlink'], max_accepted_payout=max_accepted_payout, DB.query(sql, author=op['author'], permlink=op['permlink'], max_accepted_payout=max_accepted_payout,
...@@ -389,7 +390,7 @@ class Posts: ...@@ -389,7 +390,7 @@ class Posts:
depth = result['depth'] depth = result['depth']
if depth == 0: if depth == 0:
# TODO: delete from hive_reblogs -- otherwise feed cache gets # TODO: delete from hive_reblogs -- otherwise feed cache gets
# populated with deleted posts somwrimas # populated with deleted posts somwrimas
FeedCache.delete(pid) FeedCache.delete(pid)
...@@ -442,7 +443,7 @@ class Posts: ...@@ -442,7 +443,7 @@ class Posts:
log.info("New body definition: {}".format(new_body_def)) log.info("New body definition: {}".format(new_body_def))
log.info("Old body definition: {}".format(old_body)) log.info("Old body definition: {}".format(old_body))
new_body = new_body_def new_body = new_body_def
return new_body return new_body
......
Subproject commit ee20b992bb7dae36ea964bde1e3b7f58b103dae6 Subproject commit 867e5fbf16d65a5f2db3e2b705e11b0093fb8929
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment