Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure generated tags have a valid length #6615

Merged
merged 1 commit into from
Dec 2, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/tribler-core/tribler_core/components/metadata_store/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

from pony.orm import db_session

from tribler_common.tag_constants import MIN_TAG_LENGTH

from tribler_core.components.metadata_store.db.store import MetadataStore
from tribler_core.components.tag.community.tag_payload import TagOperation
from tribler_core.components.tag.db.tag_db import TagDatabase, TagOperationEnum
Expand All @@ -32,10 +34,17 @@ def generate_title(words_count=5):
return fake.sentence(nb_words=words_count)[:-1]


def get_random_word(min_length=0):
word = fake.word()
while len(word) < min_length:
word = fake.word()
return word


def tag_torrent(infohash, tags_db, tags=None, suggested_tags=None):
tags = tags or [fake.word()
tags = tags or [get_random_word(min_length=MIN_TAG_LENGTH)
for _ in range(random.randint(2, 6))]
suggested_tags = suggested_tags or [fake.word()
suggested_tags = suggested_tags or [get_random_word(min_length=MIN_TAG_LENGTH)
for _ in range(random.randint(1, 3))]

# Give each torrent some tags
Expand Down