Skip to content

Commit

Permalink
fix: [tracker] global tracker list: fix first/last seen
Browse files Browse the repository at this point in the history
  • Loading branch information
Terrtia committed Aug 27, 2021
1 parent fb73c25 commit 57a69fa
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 20 deletions.
17 changes: 10 additions & 7 deletions bin/lib/Tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,8 @@ def fix_tracker_stats_per_day(tracker_uuid):
date_to = Date.get_today_date_str()
# delete stats
r_serv_tracker.delete(f'tracker:stat:{tracker_uuid}')
r_serv_tracker.hdel(f'tracker:{tracker_uuid}', 'first_seen')
r_serv_tracker.hdel(f'tracker:{tracker_uuid}', 'last_seen')
# create new stats
for date_day in Date.substract_date(date_from, date_to):
date_day = int(date_day)
Expand All @@ -296,22 +298,23 @@ def fix_tracker_stats_per_day(tracker_uuid):
if nb_items:
r_serv_tracker.zincrby('tracker:stat:{}'.format(tracker_uuid), int(date_day), nb_items)

# update first_seen/last_seen
update_tracker_daterange(tracker_uuid, date_day)
# update first_seen/last_seen
update_tracker_daterange(tracker_uuid, date_day)

def fix_tracker_item_link(tracker_uuid):
date_from = get_tracker_first_seen(tracker_uuid)
date_to = get_tracker_last_seen(tracker_uuid)

for date_day in Date.substract_date(date_from, date_to):
l_items = r_serv_tracker.smembers(f'tracker:item:{tracker_uuid}:{date_day}')
for item_id in l_items:
r_serv_tracker.sadd(f'obj:trackers:item:{item_id}', tracker_uuid)
if date_from and date_to:
for date_day in Date.substract_date(date_from, date_to):
l_items = r_serv_tracker.smembers(f'tracker:item:{tracker_uuid}:{date_day}')
for item_id in l_items:
r_serv_tracker.sadd(f'obj:trackers:item:{item_id}', tracker_uuid)

def fix_all_tracker_uuid_list():
r_serv_tracker.delete(f'trackers:all')
r_serv_tracker.delete(f'trackers:all:{tracker_type}')
for tracker_type in get_all_tracker_type():
r_serv_tracker.delete(f'trackers:all:{tracker_type}')
l_tracker = get_all_tracker_by_type(tracker_type)
for tracker in l_tracker:
l_tracker_uuid = get_tracker_uuid_list(tracker, tracker_type)
Expand Down
13 changes: 2 additions & 11 deletions bin/packages/Term.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,19 +431,10 @@ def parse_get_tracker_term_item(dict_input, user_id):
return (res_dict, 200)

def get_tracked_term_first_seen(term_uuid):
res = r_serv_term.zrange('tracker:stat:{}'.format(term_uuid), 0, 0)
if res:
return res[0]
else:
return None

return Tracker.get_tracker_first_seen(term_uuid)

def get_tracked_term_last_seen(term_uuid):
res = r_serv_term.zrevrange('tracker:stat:{}'.format(term_uuid), 0, 0)
if res:
return res[0]
else:
return None
return Tracker.get_tracker_last_seen(term_uuid)

def get_term_metedata(term_uuid, user_id=False, description=False, level=False, tags=False, mails=False, sparkline=False):
dict_uuid = {}
Expand Down
2 changes: 1 addition & 1 deletion update/v3.7/Update.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def update(self):
print('Fixing Tracker_uuid list ...')
Tracker.fix_all_tracker_uuid_list()
nb = 0
for tracker_uuid in get_all_tracker_uuid:
for tracker_uuid in Tracker.get_all_tracker_uuid():
self.r_serv.sadd('trackers_update_v3.7', tracker_uuid)
nb += 1

Expand Down
2 changes: 1 addition & 1 deletion update/v3.7/Update_trackers.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def update_update_stats():
nb_elem_to_update = int(nb_elem_to_update)

while True:
tracker_uuid = r_serv_onion.spop('trackers_update_v3.7')
tracker_uuid = r_serv_db.spop('trackers_update_v3.7')
if tracker_uuid is not None:
print(tracker_uuid)
# FIX STATS
Expand Down

0 comments on commit 57a69fa

Please sign in to comment.