diff --git a/src/tribler-core/tribler_core/components/tag/db/tag_db.py b/src/tribler-core/tribler_core/components/tag/db/tag_db.py index b35a265b697..3d93366bb77 100644 --- a/src/tribler-core/tribler_core/components/tag/db/tag_db.py +++ b/src/tribler-core/tribler_core/components/tag/db/tag_db.py @@ -13,7 +13,6 @@ CLOCK_START_VALUE = 0 # we picked `-1` as a value because it is allows manually created tags get a higher priority -CLOCK_FOR_AUTOGENERATED_TAGS = CLOCK_START_VALUE - 1 PUBLIC_KEY_FOR_AUTO_GENERATED_TAGS = b'auto_generated' SHOW_THRESHOLD = 1 diff --git a/src/tribler-core/tribler_core/components/tag/db/tests/test_tag_db.py b/src/tribler-core/tribler_core/components/tag/db/tests/test_tag_db.py index 87242a04b27..73315ff3fff 100644 --- a/src/tribler-core/tribler_core/components/tag/db/tests/test_tag_db.py +++ b/src/tribler-core/tribler_core/components/tag/db/tests/test_tag_db.py @@ -10,7 +10,7 @@ # pylint: disable=protected-access from tribler_core.components.tag.community.tag_payload import TagOperation, TagOperationEnum from tribler_core.components.tag.db.tag_db import ( - CLOCK_FOR_AUTOGENERATED_TAGS, + CLOCK_START_VALUE, PUBLIC_KEY_FOR_AUTO_GENERATED_TAGS, SHOW_THRESHOLD, TagDatabase, @@ -193,14 +193,13 @@ async def test_add_auto_generated_operation(self): operation=TagOperation( infohash=b'infohash', operation=TagOperationEnum.ADD, - clock=CLOCK_FOR_AUTOGENERATED_TAGS, + clock=CLOCK_START_VALUE, creator_public_key=PUBLIC_KEY_FOR_AUTO_GENERATED_TAGS, tag='tag' ) ) assert self.db.instance.TorrentTagOp.get().auto_generated - assert self.db.instance.TorrentTagOp.get().clock == CLOCK_FOR_AUTOGENERATED_TAGS assert self.db.instance.TorrentTag.get().added_count == SHOW_THRESHOLD assert self.db.instance.Peer.get().public_key == PUBLIC_KEY_FOR_AUTO_GENERATED_TAGS diff --git a/src/tribler-core/tribler_core/components/tag/rules/tag_rules.py b/src/tribler-core/tribler_core/components/tag/rules/tag_rules.py index 1fe007cd463..76b1411e77c 100644 --- a/src/tribler-core/tribler_core/components/tag/rules/tag_rules.py +++ b/src/tribler-core/tribler_core/components/tag/rules/tag_rules.py @@ -59,5 +59,7 @@ def extract_tags(text: str, rules: Optional[RulesList] = None) -> Iterable[str]: def extract_only_valid_tags(text: str, rules: Optional[RulesList] = None) -> Iterable[str]: - extracted_tags_gen = (t.lower() for t in extract_tags(text, rules)) - yield from (t for t in extracted_tags_gen if is_valid_tag(t)) + for tag in extract_tags(text, rules): + tag = tag.lower() + if is_valid_tag(tag): + yield tag diff --git a/src/tribler-core/tribler_core/components/tag/rules/tag_rules_processor.py b/src/tribler-core/tribler_core/components/tag/rules/tag_rules_processor.py index 13085e67877..ce43a09ba03 100644 --- a/src/tribler-core/tribler_core/components/tag/rules/tag_rules_processor.py +++ b/src/tribler-core/tribler_core/components/tag/rules/tag_rules_processor.py @@ -10,8 +10,7 @@ from tribler_core.components.metadata_store.db.serialization import REGULAR_TORRENT from tribler_core.components.tag.community.tag_payload import TagOperation, TagOperationEnum from tribler_core.components.tag.db.tag_db import ( - CLOCK_FOR_AUTOGENERATED_TAGS, - PUBLIC_KEY_FOR_AUTO_GENERATED_TAGS, + CLOCK_START_VALUE, PUBLIC_KEY_FOR_AUTO_GENERATED_TAGS, TagDatabase, ) from tribler_core.components.tag.rules.tag_rules import extract_only_valid_tags @@ -88,7 +87,7 @@ def save_tags(self, infohash: bytes, tags: Set[str]): operation = TagOperation( infohash=infohash, operation=TagOperationEnum.ADD, - clock=CLOCK_FOR_AUTOGENERATED_TAGS, + clock=CLOCK_START_VALUE, creator_public_key=PUBLIC_KEY_FOR_AUTO_GENERATED_TAGS, tag=tag ) diff --git a/src/tribler-core/tribler_core/components/tag/rules/tests/test_tag_rules_processor.py b/src/tribler-core/tribler_core/components/tag/rules/tests/test_tag_rules_processor.py index d1580381a43..ab3402d9f3c 100644 --- a/src/tribler-core/tribler_core/components/tag/rules/tests/test_tag_rules_processor.py +++ b/src/tribler-core/tribler_core/components/tag/rules/tests/test_tag_rules_processor.py @@ -5,7 +5,8 @@ from tribler_core.components.metadata_store.db.orm_bindings.torrent_metadata import NEW_TORRENT_METADATA_CREATED from tribler_core.components.tag.community.tag_payload import TagOperation, TagOperationEnum -from tribler_core.components.tag.db.tag_db import CLOCK_FOR_AUTOGENERATED_TAGS, PUBLIC_KEY_FOR_AUTO_GENERATED_TAGS +from tribler_core.components.tag.db.tag_db import CLOCK_START_VALUE, \ + PUBLIC_KEY_FOR_AUTO_GENERATED_TAGS from tribler_core.components.tag.rules.tag_rules_processor import LAST_PROCESSED_TORRENT_ID, TagRulesProcessor TEST_BATCH_SIZE = 100 @@ -44,11 +45,11 @@ def test_process_torrent_file(mocked_save_tags: Mock, tag_rules_processor: TagRu def test_save_tags(tag_rules_processor: TagRulesProcessor): # test that tag_rules_processor calls TagDatabase with correct args expected_calls = [{'operation': TagOperation(infohash=b'infohash', operation=TagOperationEnum.ADD, - clock=CLOCK_FOR_AUTOGENERATED_TAGS, + clock=CLOCK_START_VALUE, creator_public_key=PUBLIC_KEY_FOR_AUTO_GENERATED_TAGS, tag='tag1')}, {'operation': TagOperation(infohash=b'infohash', operation=TagOperationEnum.ADD, - clock=CLOCK_FOR_AUTOGENERATED_TAGS, + clock=CLOCK_START_VALUE, creator_public_key=PUBLIC_KEY_FOR_AUTO_GENERATED_TAGS, tag='tag2')}]