Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision

Target

Select target project
  • hive/hivemind
1 result
Select Git revision
Show changes
Commits on Source (11)
...@@ -110,6 +110,7 @@ class DbState: ...@@ -110,6 +110,7 @@ class DbState:
'hive_posts_sc_trend_id_is_paidout_idx', 'hive_posts_sc_trend_id_is_paidout_idx',
'hive_posts_sc_hot_id_is_paidout_idx', 'hive_posts_sc_hot_id_is_paidout_idx',
'hive_posts_block_num_idx', 'hive_posts_block_num_idx',
'hive_posts_block_num_created_idx',
'hive_posts_cashout_time_id_idx', 'hive_posts_cashout_time_id_idx',
'hive_posts_updated_at_idx', 'hive_posts_updated_at_idx',
'hive_posts_payout_plus_pending_payout_id_is_paidout_idx', 'hive_posts_payout_plus_pending_payout_id_is_paidout_idx',
......
...@@ -6,18 +6,13 @@ LANGUAGE 'plpgsql' ...@@ -6,18 +6,13 @@ LANGUAGE 'plpgsql'
AS AS
$function$ $function$
DECLARE DECLARE
__head_block_time TIMESTAMP; __90_days_beyond_head_block_number INTEGER;
BEGIN BEGIN
__head_block_time = head_block_time(); __90_days_beyond_head_block_number = block_before_head('90 days'::interval);
DELETE FROM hive_mentions hm DELETE FROM hive_mentions
WHERE post_id in WHERE block_num < __90_days_beyond_head_block_number;
(
SELECT id
FROM hive_posts
WHERE created_at < ( __head_block_time - '90 days'::interval )
);
END END
$function$ $function$
......
...@@ -85,6 +85,15 @@ class Follow(DbAdapterHolder): ...@@ -85,6 +85,15 @@ class Follow(DbAdapterHolder):
"""Handles processing of incoming follow ups and flushing to db.""" """Handles processing of incoming follow ups and flushing to db."""
follow_items_to_flush = dict() follow_items_to_flush = dict()
# [DK] this dictionary will hold data for table update operations
# since for each status update query is different we will group
# follower id per status:
# {
# state_number_1 : [follower_id_1, follower_id_2, ...]
# state_number_2 : [follower_id_3, follower_id_4, ...]
# }
# we will use this dict later to perform batch updates
follow_update_items_to_flush = dict() follow_update_items_to_flush = dict()
@classmethod @classmethod
...@@ -126,6 +135,9 @@ class Follow(DbAdapterHolder): ...@@ -126,6 +135,9 @@ class Follow(DbAdapterHolder):
Follow.unfollow(op['flr'], following_id) Follow.unfollow(op['flr'], following_id)
if state > 8: if state > 8:
# check if given state exists in dict
# if exists add follower to a list for a given state
# if not exists create list and set that list for given state
if state in cls.follow_update_items_to_flush: if state in cls.follow_update_items_to_flush:
cls.follow_update_items_to_flush[state].append(op['flr']) cls.follow_update_items_to_flush[state].append(op['flr'])
else: else:
...@@ -271,6 +283,12 @@ class Follow(DbAdapterHolder): ...@@ -271,6 +283,12 @@ class Follow(DbAdapterHolder):
cls.commitTx() cls.commitTx()
cls.follow_items_to_flush.clear() cls.follow_items_to_flush.clear()
# process follow_update_items_to_flush dictionary
# .items() will return list of tuples: [(state_number, [list of follower ids]), ...]
# for each state get list of follower_id and make update query
# for that list, if list size is greater than 1000 it will be divided
# to chunks of 1000
#
for state, update_flush_items in cls.follow_update_items_to_flush.items(): for state, update_flush_items in cls.follow_update_items_to_flush.items():
for chunk in chunks(update_flush_items, 1000): for chunk in chunks(update_flush_items, 1000):
sql = None sql = None
......
...@@ -53,6 +53,7 @@ async def get_post(context, author, permlink, observer=None): ...@@ -53,6 +53,7 @@ async def get_post(context, author, permlink, observer=None):
#TODO: `observer` logic for user-post state #TODO: `observer` logic for user-post state
db = context['db'] db = context['db']
valid_account(author) valid_account(author)
valid_account(observer, allow_empty=True)
valid_permlink(permlink) valid_permlink(permlink)
blacklists_for_user = None blacklists_for_user = None
...@@ -237,7 +238,7 @@ async def get_ranked_posts(context, sort:str, start_author:str='', start_permlin ...@@ -237,7 +238,7 @@ async def get_ranked_posts(context, sort:str, start_author:str='', start_permlin
for row in sql_result: for row in sql_result:
post = _bridge_post_object(row) post = _bridge_post_object(row)
post['active_votes'] = await find_votes_impl(db, row['author'], row['permlink'], VotesPresentation.BridgeApi) post['active_votes'] = await find_votes_impl(db, row['author'], row['permlink'], VotesPresentation.BridgeApi)
post = append_statistics_to_post(post, row, False, blacklists_for_user) post = append_statistics_to_post(post, row, row['is_pinned'], blacklists_for_user)
posts.append(post) posts.append(post)
return posts return posts
...@@ -286,6 +287,7 @@ async def get_account_posts(context, sort:str, account:str, start_author:str='', ...@@ -286,6 +287,7 @@ async def get_account_posts(context, sort:str, account:str, start_author:str='',
account = valid_account(account) account = valid_account(account)
start_author = valid_account(start_author, allow_empty=True) start_author = valid_account(start_author, allow_empty=True)
start_permlink = valid_permlink(start_permlink, allow_empty=True) start_permlink = valid_permlink(start_permlink, allow_empty=True)
observer = valid_account(observer, allow_empty=True)
limit = valid_limit(limit, 100, 20) limit = valid_limit(limit, 100, 20)
sql = None sql = None
...@@ -304,8 +306,6 @@ async def get_account_posts(context, sort:str, account:str, start_author:str='', ...@@ -304,8 +306,6 @@ async def get_account_posts(context, sort:str, account:str, start_author:str='',
elif sort == 'payout': elif sort == 'payout':
sql = "SELECT * FROM bridge_get_account_posts_by_payout( (:account)::VARCHAR, (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT )" sql = "SELECT * FROM bridge_get_account_posts_by_payout( (:account)::VARCHAR, (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT )"
observer = valid_account(observer, allow_empty=True)
sql_result = await db.query_all(sql, account=account, author=start_author, permlink=start_permlink, limit=limit ) sql_result = await db.query_all(sql, account=account, author=start_author, permlink=start_permlink, limit=limit )
posts = [] posts = []
blacklists_for_user = None blacklists_for_user = None
......
Subproject commit a67fd2e56ecf35b254d5f901767802524fe6f39e Subproject commit 3d3daf0c67b9d429be51b2d66543a57c0f8fcf29