Skip to content
Snippets Groups Projects
Unverified Commit aa15d55b authored by roadscape's avatar roadscape Committed by GitHub
Browse files

Merge pull request #145 from steemit/115-comment-counts

fix child counts
parents 55bcbd75 f288d1cb
No related branches found
No related tags found
No related merge requests found
...@@ -17,7 +17,7 @@ log = logging.getLogger(__name__) ...@@ -17,7 +17,7 @@ log = logging.getLogger(__name__)
DB = Db.instance() DB = Db.instance()
# levels of post dirtiness, in order of decreasing priority # levels of post dirtiness, in order of decreasing priority
LEVELS = ['insert', 'payout', 'update', 'upvote'] LEVELS = ['insert', 'payout', 'update', 'upvote', 'recount']
def _keyify(items): def _keyify(items):
return dict(map(lambda x: ("val_%d" % x[0], x[1]), enumerate(items))) return dict(map(lambda x: ("val_%d" % x[0], x[1]), enumerate(items)))
...@@ -74,6 +74,11 @@ class CachedPost: ...@@ -74,6 +74,11 @@ class CachedPost:
return cls._ids[url] return cls._ids[url]
raise Exception("requested id for %s not in map" % url) raise Exception("requested id for %s not in map" % url)
@classmethod
def recount(cls, author, permlink, pid=None):
"""Force a child re-count."""
cls._dirty('recount', author, permlink, pid)
@classmethod @classmethod
def vote(cls, author, permlink, pid=None): def vote(cls, author, permlink, pid=None):
"""Handle a post dirtied by a `vote` op.""" """Handle a post dirtied by a `vote` op."""
...@@ -452,6 +457,10 @@ class CachedPost: ...@@ -452,6 +457,10 @@ class CachedPost:
('children', "%d" % min(post['children'], 32767)), # TODO: #115 ('children', "%d" % min(post['children'], 32767)), # TODO: #115
]) ])
# if recounting, update the parent next pass.
if level == 'recount' and post['depth']:
cls.recount(post['parent_author'], post['parent_permlink'])
# build the post insert/update SQL, add tag SQLs # build the post insert/update SQL, add tag SQLs
if level == 'insert': if level == 'insert':
sql = cls._insert(values) sql = cls._insert(values)
......
...@@ -127,6 +127,9 @@ class Posts: ...@@ -127,6 +127,9 @@ class Posts:
if not DbState.is_initial_sync(): if not DbState.is_initial_sync():
CachedPost.insert(op['author'], op['permlink'], post['id']) CachedPost.insert(op['author'], op['permlink'], post['id'])
if op['parent_author']: # update parent's child count
CachedPost.recount(op['parent_author'],
op['parent_permlink'], post['parent_id'])
cls._insert_feed_cache(post) cls._insert_feed_cache(post)
@classmethod @classmethod
......
...@@ -185,19 +185,17 @@ class Sync: ...@@ -185,19 +185,17 @@ class Sync:
ms = (perf() - start_time) * 1000 ms = (perf() - start_time) * 1000
log.info("[LIVE] Got block %d at %s --% 4d txs,% 3d posts,% 3d edits," log.info("[LIVE] Got block %d at %s --% 4d txs,% 3d posts,% 3d edits,"
"% 3d payouts,% 3d votes,% 3d accts,% 3d follows --% 5dms%s", "% 3d payouts,% 3d votes,% 3d counts,% 3d accts,% 3d follows"
num, block['timestamp'], len(block['transactions']), " --% 5dms%s", num, block['timestamp'], len(block['transactions']),
cnt['insert'], cnt['update'], cnt['payout'], cnt['upvote'], cnt['insert'], cnt['update'], cnt['payout'], cnt['upvote'],
accts, follows, int(ms), ' SLOW' if ms > 1000 else '') cnt['recount'], accts, follows, ms, ' SLOW' if ms > 1000 else '')
# once per hour, update accounts #if num % 1200 == 0: #1hr
if num % 120 == 0: # Accounts.update_ranks() #144
Accounts.dirty_oldest(10000) if num % 100 == 0: #5min
Accounts.dirty_oldest(500)
Accounts.flush(steemd, trx=True) Accounts.flush(steemd, trx=True)
#Accounts.update_ranks() if num % 20 == 0: #1min
# once a minute, update chain props
if num % 20 == 0:
self._update_chain_state() self._update_chain_state()
# refetch dynamic_global_properties, feed price, etc # refetch dynamic_global_properties, feed price, etc
......
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