start trending calculation as wallet server sync nears best height

This commit is contained in:
Lex Berezhny 2019-05-19 20:22:25 -04:00
parent b8897223ec
commit c2fbbadc69
4 changed files with 10 additions and 6 deletions

View file

@ -82,7 +82,7 @@ class LBRYBlockProcessor(BlockProcessor):
def advance_txs(self, height, txs, header):
timer = self.timer.sub_timers['advance_blocks']
undo = timer.run(super().advance_txs, height, txs, header, timer_name='super().advance_txs')
timer.run(self.sql.advance_txs, height, txs, header, forward_timer=True)
timer.run(self.sql.advance_txs, height, txs, header, self.daemon.cached_height(), forward_timer=True)
if (height % 10000 == 0 or not self.db.first_sync) and self.logger.isEnabledFor(20):
self.timer.show(height=height)
return undo

View file

@ -413,7 +413,7 @@ class SQLDB:
r(self._update_effective_amount, height)
r(self._perform_overtake, height, [], [])
def advance_txs(self, height, all_txs, header, timer):
def advance_txs(self, height, all_txs, header, daemon_height, timer):
insert_claims = set()
update_claims = set()
delete_claim_hashes = set()
@ -457,8 +457,7 @@ class SQLDB:
r(self.update_claims, update_claims, header)
r(self.insert_supports, insert_supports)
r(self.update_claimtrie, height, recalculate_claim_hashes, deleted_claim_names, forward_timer=True)
if not self.main.first_sync:
r(calculate_trending, self.db, height)
r(calculate_trending, self.db, height, self.main.first_sync, daemon_height)
def get_claims(self, cols, **constraints):
if 'order_by' in constraints:

View file

@ -47,7 +47,11 @@ def register_trending_functions(connection):
connection.create_aggregate("zscore", 1, ZScore)
def calculate_trending(db, height):
def calculate_trending(db, height, is_first_sync, final_height):
# don't start tracking until we're at the end of initial sync
if is_first_sync and height < (final_height - (TRENDING_WINDOW*TRENDING_DATA_POINTS)):
return
if height % TRENDING_WINDOW != 0:
return

View file

@ -39,6 +39,7 @@ class TestSQLDB(unittest.TestCase):
def setUp(self):
self.first_sync = False
self.daemon_height = 1
self.sql = SQLDB(self, ':memory:')
self.timer = Timer('BlockProcessor')
self.sql.open()
@ -115,7 +116,7 @@ class TestSQLDB(unittest.TestCase):
def advance(self, height, txs):
self._current_height = height
self.sql.advance_txs(height, txs, {'timestamp': 1}, self.timer)
self.sql.advance_txs(height, txs, {'timestamp': 1}, self.daemon_height, self.timer)
return [otx[0].tx.outputs[0] for otx in txs]
def state(self, controlling=None, active=None, accepted=None):