Skip to content

Commit

Permalink
Merge pull request #6615 from devos50/fix_tag_generation
Browse files Browse the repository at this point in the history
Make sure generated tags have a valid length
  • Loading branch information
devos50 authored Dec 2, 2021
2 parents 5fec702 + 272661b commit d3df8bf
Showing 1 changed file with 11 additions and 2 deletions.
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

0 comments on commit d3df8bf

Please sign in to comment.