fix(sql-library): load saved files earlier at startup

This commit is contained in:
t8y2 committed 2026-09-25 14:06:37 +08:00
1 parent cb16b0f8be
commit b99c60aff6
5 files changed
+63 -16

No files matched your search

+9 -9
View File
@@ -3870,6 +3870,15 @@ function onLoginSuccess() {
async function initApp() {
const t0 = performance.now();
console.log("[STARTUP] initApp begin");
void Promise.all([initSavedSqlEditorPositions(), savedSqlStore.initFromStorage()])
.then(() => {
console.log(`[STARTUP] savedSqlStore.initFromStorage: ${(performance.now() - t0).toFixed(0)}ms`);
void queryStore.hydrateSavedSqlTabs();
})
.catch((e: any) => {
toast(t("connection.loadFailed", { message: e?.message || String(e) }), 5000);
});
const restoreOpenTabs = async () => {
await settingsStore.initEditorSettings();
markStartupPhase("settings-ready");
@@ -3916,15 +3925,6 @@ async function initApp() {
void promptTemplateStore.init();
void Promise.all([initSavedSqlEditorPositions(), savedSqlStore.initFromStorage()])
.then(() => {
console.log(`[STARTUP] savedSqlStore.initFromStorage: ${(performance.now() - t0).toFixed(0)}ms`);
void queryStore.hydrateSavedSqlTabs();
})
.catch((e: any) => {
toast(t("connection.loadFailed", { message: e?.message || String(e) }), 5000);
});
restoreActiveConnectionContext();
} catch (e: any) {
toast(t("connection.loadFailed", { message: e?.message || String(e) }), 5000);
@@ -2,7 +2,7 @@
import { computed, nextTick, onBeforeUnmount, reactive, ref, watch } from "vue";
import type { CSSProperties } from "vue";
import { useI18n } from "vue-i18n";
import { ArrowDownWideNarrow, ChevronsDownUp, Download, FilePlus, FileText, FolderCog, FolderClosed, FolderOpen, FolderPlus, Library, LocateFixed, Pencil, Play, Search, Trash2, Upload, X } from "@lucide/vue";
import { ArrowDownWideNarrow, ChevronsDownUp, Download, FilePlus, FileText, FolderCog, FolderClosed, FolderOpen, FolderPlus, Library, Loader2, LocateFixed, Pencil, Play, Search, Trash2, Upload, X } from "@lucide/vue";
import { Button } from "@/components/ui/button";
import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from "@/components/ui/dialog";
import CustomContextMenu, { type ContextMenuItem as CtxMenuItem } from "@/components/ui/CustomContextMenu.vue";
@@ -1446,7 +1446,12 @@ function showDropInside(targetId: string) {
</div>
<!-- End tree structure -->
<div v-if="!hasAnyVisibleItem" class="flex h-full flex-col items-center justify-center gap-2 text-muted-foreground">
<div v-if="savedSqlStore.loadState === 'idle' || savedSqlStore.loadState === 'loading'" class="flex h-full flex-col items-center justify-center gap-2 text-muted-foreground" role="status" aria-live="polite">
<Loader2 class="h-6 w-6 animate-spin motion-reduce:animate-none" aria-hidden="true" />
<p class="text-[13px]">{{ t("common.loading") }}</p>
</div>
<div v-else-if="!hasAnyVisibleItem" class="flex h-full flex-col items-center justify-center gap-2 text-muted-foreground">
<Library class="h-8 w-8 opacity-30" />
<p class="text-[13px]">{{ t("sqlLibrary.empty") }}</p>
</div>
+12 -3
View File
@@ -148,6 +148,7 @@ export const useSavedSqlStore = defineStore("savedSql", () => {
const folders = ref<SavedSqlFolder[]>([]);
const files = ref<SavedSqlFile[]>([]);
const isLoaded = ref(false);
const loadState = ref<"idle" | "loading" | "loaded" | "failed">("idle");
let pendingSync: Promise<void> | null = null;
let initFromStoragePromise: Promise<void> | null = null;
const pendingFolderCreates = new Map<string, Promise<SavedSqlFolder>>();
@@ -186,13 +187,20 @@ export const useSavedSqlStore = defineStore("savedSql", () => {
async function initFromStorage() {
if (isLoaded.value) return;
if (!initFromStoragePromise) {
loadState.value = "loading";
initFromStoragePromise = (async () => {
await migrateLegacyLocalStorage();
applyLibrary(await api.loadSavedSqlLibrary());
isLoaded.value = true;
})().finally(() => {
initFromStoragePromise = null;
});
loadState.value = "loaded";
})()
.catch((error) => {
loadState.value = "failed";
throw error;
})
.finally(() => {
initFromStoragePromise = null;
});
}
await initFromStoragePromise;
}
@@ -821,6 +829,7 @@ export const useSavedSqlStore = defineStore("savedSql", () => {
folders,
files,
isLoaded,
loadState,
version,
treeVersion,
initFromStorage,