diff --git a/lbrynet/wallet/server/block_processor.py b/lbrynet/wallet/server/block_processor.py index b81261f6e..4db440402 100644 --- a/lbrynet/wallet/server/block_processor.py +++ b/lbrynet/wallet/server/block_processor.py @@ -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 diff --git a/lbrynet/wallet/server/db.py b/lbrynet/wallet/server/db.py index 027f327f3..41a783190 100644 --- a/lbrynet/wallet/server/db.py +++ b/lbrynet/wallet/server/db.py @@ -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: diff --git a/lbrynet/wallet/server/trending.py b/lbrynet/wallet/server/trending.py index 87f245963..6b5e85bcf 100644 --- a/lbrynet/wallet/server/trending.py +++ b/lbrynet/wallet/server/trending.py @@ -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 diff --git a/tests/unit/wallet/server/test_sqldb.py b/tests/unit/wallet/server/test_sqldb.py index 550b25767..7422171e8 100644 --- a/tests/unit/wallet/server/test_sqldb.py +++ b/tests/unit/wallet/server/test_sqldb.py @@ -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):