Skip to content

Commit

Permalink
🧹 Tags: remove double get, sort tags (#5620)
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).

**How to test**

Unsorted tags should be sorted after adding a tag. Otherwise no functional difference.
  • Loading branch information
rix0rrr authored Jun 25, 2024
1 parent 1fb6676 commit 5de8f29
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ describe("Tags of adventures", () => {
}).as("deleteTag")

cy.wait(500)
cy.get("#tag_2")
cy.get("#tag_1")
.should("be.visible")
.should("include.text", "statements")
cy.get("#tag_2 .fa-circle-xmark")
cy.get("#tag_1 .fa-circle-xmark")
.click()
cy.wait("@deleteTag").should('have.nested.property', 'response.statusCode', 200)
cy.get("#tags_list li")
Expand Down
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 Down Expand Up @@ -58,6 +57,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 5de8f29

Please sign in to comment.