优化模型字典加载缓存
This commit is contained in:
@@ -5,8 +5,8 @@ DB_PATH=
|
|||||||
|
|
||||||
# login: show login page
|
# login: show login page
|
||||||
# fixed: auto login with FIXED_LOGIN_USERNAME and open model library directly
|
# fixed: auto login with FIXED_LOGIN_USERNAME and open model library directly
|
||||||
APP_AUTH_MODE=fixed
|
APP_AUTH_MODE=login
|
||||||
FIXED_LOGIN_USERNAME=viewer
|
FIXED_LOGIN_USERNAME=
|
||||||
FIXED_LOGIN_ROLE=user
|
FIXED_LOGIN_ROLE=user
|
||||||
ALLOW_USER_EDIT_SYSTEM_LIBRARY=false
|
ALLOW_USER_EDIT_SYSTEM_LIBRARY=false
|
||||||
|
|
||||||
|
|||||||
@@ -22,6 +22,8 @@ type UploadModelPayload = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const defaultOperationTree = JSON.stringify({ OperationTree: "[]" });
|
const defaultOperationTree = JSON.stringify({ OperationTree: "[]" });
|
||||||
|
let dictionariesLoaded = false;
|
||||||
|
let dictionariesLoading: Promise<void> | null = null;
|
||||||
|
|
||||||
export function bindModelActions() {
|
export function bindModelActions() {
|
||||||
const isAdmin = getCurrentUser()?.role === "admin";
|
const isAdmin = getCurrentUser()?.role === "admin";
|
||||||
@@ -38,7 +40,10 @@ export function bindModelActions() {
|
|||||||
document.querySelector("#manageDictionariesBtn")?.addEventListener("click", async () => {
|
document.querySelector("#manageDictionariesBtn")?.addEventListener("click", async () => {
|
||||||
try {
|
try {
|
||||||
const { openDictionaryManager } = await import("./dictionaries");
|
const { openDictionaryManager } = await import("./dictionaries");
|
||||||
await openDictionaryManager(loadModels);
|
await openDictionaryManager(async () => {
|
||||||
|
invalidateDictionaries();
|
||||||
|
await loadModels();
|
||||||
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
notifyError(error);
|
notifyError(error);
|
||||||
}
|
}
|
||||||
@@ -158,12 +163,37 @@ export async function loadModels() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function loadDictionaries() {
|
async function loadDictionaries(force = false) {
|
||||||
const result = await api<DictionaryResponse>("/api/dictionaries");
|
if (!force && dictionariesLoaded) {
|
||||||
appState.brands = result.brands;
|
syncDictionaryFilters();
|
||||||
appState.types = result.types;
|
return;
|
||||||
syncDictionarySelect("#brandFilter", result.brands, "全部品牌", appState.filters.brandId);
|
}
|
||||||
syncDictionarySelect("#typeFilter", result.types, "全部类型", appState.filters.typeId);
|
if (!force && dictionariesLoading) {
|
||||||
|
await dictionariesLoading;
|
||||||
|
syncDictionaryFilters();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
dictionariesLoading = api<DictionaryResponse>("/api/dictionaries")
|
||||||
|
.then((result) => {
|
||||||
|
appState.brands = result.brands;
|
||||||
|
appState.types = result.types;
|
||||||
|
dictionariesLoaded = true;
|
||||||
|
})
|
||||||
|
.finally(() => {
|
||||||
|
dictionariesLoading = null;
|
||||||
|
});
|
||||||
|
await dictionariesLoading;
|
||||||
|
syncDictionaryFilters();
|
||||||
|
}
|
||||||
|
|
||||||
|
function invalidateDictionaries() {
|
||||||
|
dictionariesLoaded = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function syncDictionaryFilters() {
|
||||||
|
syncDictionarySelect("#brandFilter", appState.brands, "全部品牌", appState.filters.brandId);
|
||||||
|
syncDictionarySelect("#typeFilter", appState.types, "全部类型", appState.filters.typeId);
|
||||||
}
|
}
|
||||||
|
|
||||||
function syncDictionarySelect(selector: string, items: { id: number; name: string }[], emptyText: string, value: string) {
|
function syncDictionarySelect(selector: string, items: { id: number; name: string }[], emptyText: string, value: string) {
|
||||||
@@ -312,6 +342,7 @@ async function openUploadModelDialog() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (result) {
|
if (result) {
|
||||||
|
invalidateDictionaries();
|
||||||
await loadModels();
|
await loadModels();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -391,6 +422,7 @@ export async function openProcessModelUploadDialog(input?: {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (result) {
|
if (result) {
|
||||||
|
invalidateDictionaries();
|
||||||
await loadModels();
|
await loadModels();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -565,6 +597,7 @@ async function editModel(id: number) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
invalidateDictionaries();
|
||||||
await loadModels();
|
await loadModels();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user