Fix Incorrect Method Call and Potential Race Condition in src/db/index.ts
- Corrected deleteChatHistory method call to include id parameter. - Addressed potential race condition in addMessage method to handle simultaneous message additions.
This commit is contained in:
		
							parent
							
								
									579d8ea58c
								
							
						
					
					
						commit
						128bf57171
					
				| @ -89,7 +89,7 @@ export class PageAssitDatabase { | ||||
|     const history_id = message.history_id | ||||
|     const chatHistory = await this.getChatHistory(history_id) | ||||
|     const newChatHistory = [message, ...chatHistory] | ||||
|     this.db.set({ [history_id]: newChatHistory }) | ||||
|     await this.db.set({ [history_id]: newChatHistory }) | ||||
|   } | ||||
| 
 | ||||
|   async removeChatHistory(id: string) { | ||||
| @ -112,12 +112,13 @@ export class PageAssitDatabase { | ||||
|     this.db.clear() | ||||
|   } | ||||
| 
 | ||||
|   async deleteChatHistory() { | ||||
|   async deleteChatHistory(id: string) { | ||||
|     const chatHistories = await this.getChatHistories() | ||||
|     for (const history of chatHistories) { | ||||
|       this.db.remove(history.id) | ||||
|     } | ||||
|     this.db.remove("chatHistories") | ||||
|     const newChatHistories = chatHistories.filter( | ||||
|       (history) => history.id !== id | ||||
|     ) | ||||
|     this.db.set({ chatHistories: newChatHistories }) | ||||
|     this.db.remove(id) | ||||
|   } | ||||
| 
 | ||||
|   async deleteMessage(history_id: string) { | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user