Add guard against redundant folder API calls on repeated focus events
Co-authored-by: jbatesy <51190172+jbatesy@users.noreply.github.com>
This commit is contained in:
parent
66bfc4cf99
commit
1f99666f7e
1 changed files with 5 additions and 0 deletions
|
|
@ -6,6 +6,7 @@ import type { ConfigFeature, ConfigUpdateAction } from '~/types/sockets';
|
|||
import { request } from '~/utils';
|
||||
|
||||
let last_reload = 0;
|
||||
let folders_loaded = false;
|
||||
const CONFIG_TTL = 10;
|
||||
|
||||
export const useConfigStore = defineStore('config', () => {
|
||||
|
|
@ -96,6 +97,9 @@ export const useConfigStore = defineStore('config', () => {
|
|||
};
|
||||
|
||||
const loadFolders = async () => {
|
||||
if (folders_loaded) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const resp = await request('/api/system/folders', { timeout: 10 });
|
||||
if (!resp.ok) {
|
||||
|
|
@ -104,6 +108,7 @@ export const useConfigStore = defineStore('config', () => {
|
|||
const data = await resp.json();
|
||||
if (Array.isArray(data.folders)) {
|
||||
state.folders = data.folders;
|
||||
folders_loaded = true;
|
||||
}
|
||||
} catch (e: any) {
|
||||
console.error(`Failed to load folders: ${e}`);
|
||||
|
|
|
|||
Loading…
Reference in a new issue