forked from open-webui/open-webui
		
	feat: chat cascade delete
This commit is contained in:
		
							parent
							
								
									eca59f759d
								
							
						
					
					
						commit
						95505bc4c1
					
				
					 1 changed files with 15 additions and 1 deletions
				
			
		|  | @ -224,7 +224,7 @@ class ChatTable: | ||||||
|             query = Chat.delete().where((Chat.id == id) & (Chat.user_id == user_id)) |             query = Chat.delete().where((Chat.id == id) & (Chat.user_id == user_id)) | ||||||
|             query.execute()  # Remove the rows, return number of rows removed. |             query.execute()  # Remove the rows, return number of rows removed. | ||||||
| 
 | 
 | ||||||
|             return True |             return True and self.delete_shared_chat_by_chat_id(id) | ||||||
|         except: |         except: | ||||||
|             return False |             return False | ||||||
| 
 | 
 | ||||||
|  | @ -233,6 +233,20 @@ class ChatTable: | ||||||
|             query = Chat.delete().where(Chat.user_id == user_id) |             query = Chat.delete().where(Chat.user_id == user_id) | ||||||
|             query.execute()  # Remove the rows, return number of rows removed. |             query.execute()  # Remove the rows, return number of rows removed. | ||||||
| 
 | 
 | ||||||
|  |             return True and self.delete_shared_chats_by_user_id(user_id) | ||||||
|  |         except: | ||||||
|  |             return False | ||||||
|  | 
 | ||||||
|  |     def delete_shared_chats_by_user_id(self, user_id: str) -> bool: | ||||||
|  |         try: | ||||||
|  |             shared_chat_ids = [ | ||||||
|  |                 f"shared-{chat.id}" | ||||||
|  |                 for chat in Chat.select().where(Chat.user_id == user_id) | ||||||
|  |             ] | ||||||
|  | 
 | ||||||
|  |             query = Chat.delete().where(Chat.user_id << shared_chat_ids) | ||||||
|  |             query.execute()  # Remove the rows, return number of rows removed. | ||||||
|  | 
 | ||||||
|             return True |             return True | ||||||
|         except: |         except: | ||||||
|             return False |             return False | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Timothy J. Baek
						Timothy J. Baek