throttling saveConfigs

This commit is contained in:
josc146 2024-03-26 21:27:26 +08:00
parent 3cef51144f
commit 0ab248c478

View File

@ -2,6 +2,7 @@ import {
AddToDownloadList, AddToDownloadList,
DeleteFile, DeleteFile,
DepCheck, DepCheck,
GetProxyPort,
InstallPyDep, InstallPyDep,
ListDirFiles, ListDirFiles,
OpenOpenFileDialog, OpenOpenFileDialog,
@ -28,7 +29,7 @@ import logo from '../assets/images/logo.png';
import { Preset } from '../types/presets'; import { Preset } from '../types/presets';
import { botName, Conversation, MessageType, Role, systemName, userName } from '../types/chat'; import { botName, Conversation, MessageType, Role, systemName, userName } from '../types/chat';
import { v4 as uuid } from 'uuid'; import { v4 as uuid } from 'uuid';
import { findLastIndex } from 'lodash-es'; import { findLastIndex, throttle } from 'lodash-es';
export type Cache = { export type Cache = {
version: string version: string
@ -223,7 +224,7 @@ export const getStrategy = (modelConfig: ModelConfig | undefined = undefined) =>
return strategy; return strategy;
}; };
export const saveConfigs = async () => { export const saveConfigs = throttle(async () => {
const data: LocalConfig = { const data: LocalConfig = {
modelSourceManifestList: commonStore.modelSourceManifestList, modelSourceManifestList: commonStore.modelSourceManifestList,
currentModelConfigIndex: commonStore.currentModelConfigIndex, currentModelConfigIndex: commonStore.currentModelConfigIndex,
@ -233,7 +234,11 @@ export const saveConfigs = async () => {
loraFinetuneParams: commonStore.loraFinetuneParams loraFinetuneParams: commonStore.loraFinetuneParams
}; };
return SaveJson('config.json', data); return SaveJson('config.json', data);
}; }, 500,
{
leading: true,
trailing: true
});
export const saveCache = async () => { export const saveCache = async () => {
const data: Cache = { const data: Cache = {