Skip to content

Commit

Permalink
🧹 Tags: remove double get, sort tags
Browse files Browse the repository at this point in the history
Two tiny changes ported over from #5431:

- Remove a duplicate database retrieval when looking up the tags of an
  adventure.
- Sort the tags (when they are saved to the database).
  • Loading branch information
rix0rrr committed Jun 18, 2024
1 parent 9cd260b commit 5778b5d
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion website/tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ def get_public_tags(self, user, adventure_id):
adventure_id = request.args.get("adventure_id")
adventure = self.db.get_adventure(adventure_id)
if adventure:
adventure = self.db.get_adventure(adventure_id)
# exclude current adventure's tags
public_tags = list(filter(lambda t: t["name"] not in adventure.get("tags", []), public_tags))

Expand All @@ -56,6 +55,7 @@ def create(self, user, adventure_id, new_tag=None):
adventure_tags = db_adventure.get("tags", [])
if tag_name not in adventure_tags:
adventure_tags.append(tag_name)
adventure_tags = sorted(adventure_tags, key=lambda tag: tag)
self.db.update_adventure(adventure_id, {"tags": adventure_tags})
else:
return make_response(gettext("tag_in_adventure"), 400)
Expand Down

0 comments on commit 5778b5d

Please sign in to comment.