From 57a69fa1f4a40d2be304404dd07ed454a779e9cd Mon Sep 17 00:00:00 2001 From: Terrtia Date: Fri, 27 Aug 2021 18:53:12 +0200 Subject: [PATCH] fix: [tracker] global tracker list: fix first/last seen --- bin/lib/Tracker.py | 17 ++++++++++------- bin/packages/Term.py | 13 ++----------- update/v3.7/Update.py | 2 +- update/v3.7/Update_trackers.py | 2 +- 4 files changed, 14 insertions(+), 20 deletions(-) diff --git a/bin/lib/Tracker.py b/bin/lib/Tracker.py index d2350cc9..5310fa73 100755 --- a/bin/lib/Tracker.py +++ b/bin/lib/Tracker.py @@ -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) @@ -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) diff --git a/bin/packages/Term.py b/bin/packages/Term.py index c8389ab8..245296ae 100755 --- a/bin/packages/Term.py +++ b/bin/packages/Term.py @@ -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 = {} diff --git a/update/v3.7/Update.py b/update/v3.7/Update.py index e507b8c2..a8baa092 100755 --- a/update/v3.7/Update.py +++ b/update/v3.7/Update.py @@ -28,7 +28,7 @@ class Updater(AIL_Updater): 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 diff --git a/update/v3.7/Update_trackers.py b/update/v3.7/Update_trackers.py index fc2beef9..1474e49b 100644 --- a/update/v3.7/Update_trackers.py +++ b/update/v3.7/Update_trackers.py @@ -35,7 +35,7 @@ if __name__ == '__main__': 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