Skip to content

Commit

Permalink
PR fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
drew2a committed Jan 26, 2022
1 parent a88db81 commit 0a9212c
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
1 change: 0 additions & 1 deletion src/tribler-core/tribler_core/components/tag/db/tag_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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')}]

Expand Down

0 comments on commit 0a9212c

Please sign in to comment.