From 1d937ec2f20c81b5b8048e71506f0e7e73d252e0 Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Sun, 25 Feb 2024 13:03:26 -0800 Subject: [PATCH] fix: cleanup unused tags --- CHANGELOG.md | 5 +++-- backend/apps/web/models/tags.py | 21 +++++++++++++++++++++ backend/apps/web/routers/chats.py | 7 +++++-- src/lib/components/layout/Sidebar.svelte | 10 ++++++++-- 4 files changed, 37 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8f0d08492..32679bd42 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,11 +9,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added -- **🔄 Check for Updates**: Now conveniently available in Settings > About. +- **🔄 Check for Updates**: Keep your system current by checking for updates conveniently located in Settings > About. +- **🗑️ Automatic Tag Deletion**: Unused tags on the sidebar will now be deleted automatically with just a click. ### Changed -- **🎨 Modernized Styling**: Updated for a more contemporary appearance. +- **🎨 Modernized Styling**: Enjoy a refreshed look with updated styling for a more contemporary experience. ## [0.1.103] - 2024-02-25 diff --git a/backend/apps/web/models/tags.py b/backend/apps/web/models/tags.py index c14658cf6..d42645015 100644 --- a/backend/apps/web/models/tags.py +++ b/backend/apps/web/models/tags.py @@ -167,6 +167,27 @@ class TagTable: .count() ) + def delete_tag_by_tag_name_and_user_id(self, tag_name: str, user_id: str) -> bool: + try: + query = ChatIdTag.delete().where( + (ChatIdTag.tag_name == tag_name) & (ChatIdTag.user_id == user_id) + ) + res = query.execute() # Remove the rows, return number of rows removed. + print(res) + + tag_count = self.count_chat_ids_by_tag_name_and_user_id(tag_name, user_id) + if tag_count == 0: + # Remove tag item from Tag col as well + query = Tag.delete().where( + (Tag.name == tag_name) & (Tag.user_id == user_id) + ) + query.execute() # Remove the rows, return number of rows removed. + + return True + except Exception as e: + print("delete_tag", e) + return False + def delete_tag_by_tag_name_and_chat_id_and_user_id( self, tag_name: str, chat_id: str, user_id: str ) -> bool: diff --git a/backend/apps/web/routers/chats.py b/backend/apps/web/routers/chats.py index 00dcfb6ed..1ce537ec6 100644 --- a/backend/apps/web/routers/chats.py +++ b/backend/apps/web/routers/chats.py @@ -115,9 +115,12 @@ async def get_user_chats_by_tag_name( for chat_id_tag in Tags.get_chat_ids_by_tag_name_and_user_id(tag_name, user.id) ] - print(chat_ids) + chats = Chats.get_chat_lists_by_chat_ids(chat_ids, skip, limit) - return Chats.get_chat_lists_by_chat_ids(chat_ids, skip, limit) + if len(chats) == 0: + Tags.delete_tag_by_tag_name_and_user_id(tag_name, user.id) + + return chats ############################ diff --git a/src/lib/components/layout/Sidebar.svelte b/src/lib/components/layout/Sidebar.svelte index c1878f4b7..293979a83 100644 --- a/src/lib/components/layout/Sidebar.svelte +++ b/src/lib/components/layout/Sidebar.svelte @@ -13,7 +13,8 @@ getChatList, getChatById, getChatListByTagName, - updateChatById + updateChatById, + getAllChatTags } from '$lib/apis/chats'; import toast from 'svelte-french-toast'; import { slide } from 'svelte/transition'; @@ -330,7 +331,12 @@