forked from open-webui/open-webui
feat: delete idb after migration
This commit is contained in:
parent
e2a5964842
commit
d78df83453
3 changed files with 21 additions and 19 deletions
|
@ -119,8 +119,8 @@ class ChatTable:
|
||||||
for chat in Chat.select()
|
for chat in Chat.select()
|
||||||
.where(Chat.user_id == user_id)
|
.where(Chat.user_id == user_id)
|
||||||
.order_by(Chat.timestamp.desc())
|
.order_by(Chat.timestamp.desc())
|
||||||
.limit(limit)
|
# .limit(limit)
|
||||||
.offset(skip)
|
# .offset(skip)
|
||||||
]
|
]
|
||||||
|
|
||||||
def get_chat_by_id_and_user_id(self, id: str, user_id: str) -> Optional[ChatModel]:
|
def get_chat_by_id_and_user_id(self, id: str, user_id: str) -> Optional[ChatModel]:
|
||||||
|
|
|
@ -49,15 +49,6 @@
|
||||||
await deleteChatById(localStorage.token, id);
|
await deleteChatById(localStorage.token, id);
|
||||||
await chats.set(await getChatList(localStorage.token));
|
await chats.set(await getChatList(localStorage.token));
|
||||||
};
|
};
|
||||||
|
|
||||||
// const deleteChatHistory = async () => {
|
|
||||||
// await $db.deleteAllChat();
|
|
||||||
|
|
||||||
// const tx = this.db.transaction('chats', 'readwrite');
|
|
||||||
// await Promise.all([tx.store.clear(), tx.done]);
|
|
||||||
|
|
||||||
// await chats.set(await this.getChats());
|
|
||||||
// };
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import toast from 'svelte-french-toast';
|
import toast from 'svelte-french-toast';
|
||||||
import { openDB } from 'idb';
|
import { openDB, deleteDB } from 'idb';
|
||||||
import { onMount, tick } from 'svelte';
|
import { onMount, tick } from 'svelte';
|
||||||
import { goto } from '$app/navigation';
|
import { goto } from '$app/navigation';
|
||||||
|
|
||||||
|
@ -72,16 +72,26 @@
|
||||||
if ($user === undefined) {
|
if ($user === undefined) {
|
||||||
await goto('/auth');
|
await goto('/auth');
|
||||||
} else if (['user', 'admin'].includes($user.role)) {
|
} else if (['user', 'admin'].includes($user.role)) {
|
||||||
|
try {
|
||||||
|
// Check if IndexedDB exists
|
||||||
DB = await openDB('Chats', 1);
|
DB = await openDB('Chats', 1);
|
||||||
|
|
||||||
if (DB) {
|
if (DB) {
|
||||||
const chats = await DB.getAllFromIndex('chats', 'timestamp');
|
const chats = await DB.getAllFromIndex('chats', 'timestamp');
|
||||||
localDBChats = chats.map((item, idx) => chats[chats.length - 1 - idx]);
|
localDBChats = chats.map((item, idx) => chats[chats.length - 1 - idx]);
|
||||||
|
|
||||||
|
if (localDBChats.length === 0) {
|
||||||
|
await deleteDB('Chats');
|
||||||
|
}
|
||||||
|
|
||||||
console.log('localdb', localDBChats);
|
console.log('localdb', localDBChats);
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(DB);
|
console.log(DB);
|
||||||
|
} catch (error) {
|
||||||
|
// IndexedDB Not Found
|
||||||
|
console.log('IDB Not Found');
|
||||||
|
}
|
||||||
|
|
||||||
console.log();
|
console.log();
|
||||||
await settings.set(JSON.parse(localStorage.getItem('settings') ?? '{}'));
|
await settings.set(JSON.parse(localStorage.getItem('settings') ?? '{}'));
|
||||||
|
@ -214,6 +224,7 @@
|
||||||
|
|
||||||
const tx = DB.transaction('chats', 'readwrite');
|
const tx = DB.transaction('chats', 'readwrite');
|
||||||
await Promise.all([tx.store.clear(), tx.done]);
|
await Promise.all([tx.store.clear(), tx.done]);
|
||||||
|
await deleteDB('Chats');
|
||||||
|
|
||||||
localDBChats = [];
|
localDBChats = [];
|
||||||
}}
|
}}
|
||||||
|
|
Loading…
Reference in a new issue