From 8bf67cf3b635d53577fa05ef667c6c23a992bb8c Mon Sep 17 00:00:00 2001 From: terrtia Date: Mon, 8 Jan 2024 14:51:40 +0100 Subject: [PATCH] fix: [tags] remove invalid tags --- bin/lib/Tag.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/bin/lib/Tag.py b/bin/lib/Tag.py index af193890..ade0f026 100755 --- a/bin/lib/Tag.py +++ b/bin/lib/Tag.py @@ -635,7 +635,7 @@ def update_tag_metadata(tag, date, delete=False): # # TODO: delete Tags # r_tags.smembers(f'{tag}:{date}') # r_tags.smembers(f'{obj_type}:{tag}') def get_tag_objects(tag, obj_type, subtype='', date=''): - if obj_type == 'item': + if obj_type == 'item' or obj_type == 'message': return r_tags.smembers(f'{obj_type}:{subtype}:{tag}:{date}') else: return r_tags.smembers(f'{obj_type}:{subtype}:{tag}') @@ -716,6 +716,12 @@ def delete_object_tag(tag, obj_type, id, subtype=''): date = item_basic.get_item_date(id) r_tags.srem(f'{obj_type}:{subtype}:{tag}:{date}', id) + update_tag_metadata(tag, date, delete=True) + elif obj_type == 'message': + timestamp = id.split('/')[1] + date = datetime.datetime.fromtimestamp(float(timestamp)).strftime('%Y%m%d') + r_tags.srem(f'{obj_type}:{subtype}:{tag}:{date}', id) + update_tag_metadata(tag, date, delete=True) else: r_tags.srem(f'{obj_type}:{subtype}:{tag}', id) @@ -1458,6 +1464,18 @@ def get_list_of_solo_tags_to_export_by_type(export_type): # by type return None #r_serv_db.smembers('whitelist_hive') +def _fix_tag_obj_id(): + for obj_type in ail_core.get_all_objects(): + for tag in get_all_obj_tags(obj_type): + if ';' in tag: + new_tag = tag.split(';')[0] + for raw in get_obj_by_tags(obj_type, [new_tag], nb_obj=500000): + for global_id in raw.get('tagged_obj', []): + obj_type, subtype, obj_id = global_id.split(':', 2) + delete_object_tag(tag, obj_type, obj_id, subtype=subtype) + add_object_tag(new_tag, obj_type, obj_id, subtype=subtype) + + # if __name__ == '__main__': # taxo = 'accessnow' # # taxo = TAXONOMIES.get(taxo)