only do trending calculations near the tip of the chain
This commit is contained in:
parent
eb8a88dbd6
commit
065215cc27
2 changed files with 13 additions and 9 deletions
|
@ -1,7 +1,11 @@
|
|||
from math import sqrt
|
||||
|
||||
TRENDING_WINDOW = 134 # number of blocks in ~6hr period (21600 seconds / 161 seconds per block)
|
||||
TRENDING_DATA_POINTS = 7 # WINDOW * DATA_POINTS = ~1 week worth of trending data
|
||||
# TRENDING_WINDOW is the number of blocks in ~6hr period (21600 seconds / 161 seconds per block)
|
||||
TRENDING_WINDOW = 134
|
||||
|
||||
# TRENDING_DATA_POINTS says how many samples to use for the trending algorithm
|
||||
# i.e. only consider claims from the most recent (TRENDING_WINDOW * TRENDING_DATA_POINTS) blocks
|
||||
TRENDING_DATA_POINTS = 7
|
||||
|
||||
CREATE_TREND_TABLE = """
|
||||
create table if not exists trend (
|
||||
|
@ -47,9 +51,9 @@ def register_trending_functions(connection):
|
|||
connection.create_aggregate("zscore", 1, ZScore)
|
||||
|
||||
|
||||
def calculate_trending(db, height, is_first_sync, final_height):
|
||||
def calculate_trending(db, height, 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)):
|
||||
if height < (final_height - (TRENDING_WINDOW * TRENDING_DATA_POINTS)):
|
||||
return
|
||||
|
||||
if height % TRENDING_WINDOW != 0:
|
||||
|
|
|
@ -699,7 +699,7 @@ class SQLDB:
|
|||
update_claims, delete_claim_hashes, affected_channels, forward_timer=True)
|
||||
r(self.insert_supports, insert_supports)
|
||||
r(self.update_claimtrie, height, recalculate_claim_hashes, deleted_claim_names, forward_timer=True)
|
||||
r(calculate_trending, self.db, height, self.main.first_sync, daemon_height)
|
||||
r(calculate_trending, self.db, height, daemon_height)
|
||||
|
||||
|
||||
class LBRYDB(DB):
|
||||
|
|
Loading…
Add table
Reference in a new issue