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

Merge branch 'dk-follow-code-comments' into 'develop'

Added comments for batch update portion of the flush method

See merge request !291
parents 60a1eb4a c08055db
No related branches found
No related tags found
2 merge requests!456Release candidate v1 24,!291Added comments for batch update portion of the flush method
...@@ -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
......
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