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 history_id = message.history_id
|
||||||
const chatHistory = await this.getChatHistory(history_id)
|
const chatHistory = await this.getChatHistory(history_id)
|
||||||
const newChatHistory = [message, ...chatHistory]
|
const newChatHistory = [message, ...chatHistory]
|
||||||
this.db.set({ [history_id]: newChatHistory })
|
await this.db.set({ [history_id]: newChatHistory })
|
||||||
}
|
}
|
||||||
|
|
||||||
async removeChatHistory(id: string) {
|
async removeChatHistory(id: string) {
|
||||||
@ -112,12 +112,13 @@ export class PageAssitDatabase {
|
|||||||
this.db.clear()
|
this.db.clear()
|
||||||
}
|
}
|
||||||
|
|
||||||
async deleteChatHistory() {
|
async deleteChatHistory(id: string) {
|
||||||
const chatHistories = await this.getChatHistories()
|
const chatHistories = await this.getChatHistories()
|
||||||
for (const history of chatHistories) {
|
const newChatHistories = chatHistories.filter(
|
||||||
this.db.remove(history.id)
|
(history) => history.id !== id
|
||||||
}
|
)
|
||||||
this.db.remove("chatHistories")
|
this.db.set({ chatHistories: newChatHistories })
|
||||||
|
this.db.remove(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
async deleteMessage(history_id: string) {
|
async deleteMessage(history_id: string) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user