Skip to content

Commit c8e2e02

Browse files
committed
reload buffer (#3665)
* reload buffer * reload buffer * tts selector
1 parent 4ada33e commit c8e2e02

File tree

7 files changed

+38
-17
lines changed

7 files changed

+38
-17
lines changed

Diff for: packages/service/common/system/config/controller.ts

+10
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,13 @@ export const updateFastGPTConfigBuffer = async () => {
3939

4040
global.systemInitBufferId = res.createTime.getTime().toString();
4141
};
42+
43+
export const reloadFastGPTConfigBuffer = async () => {
44+
const res = await MongoSystemConfigs.findOne({
45+
type: SystemConfigsTypeEnum.fastgpt
46+
}).sort({
47+
createTime: -1
48+
});
49+
if (!res) return;
50+
global.systemInitBufferId = res.createTime.getTime().toString();
51+
};

Diff for: packages/service/core/ai/config/utils.ts

+18
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ import {
1313
import { debounce } from 'lodash';
1414
import { ModelProviderType } from '@fastgpt/global/core/ai/provider';
1515
import { findModelFromAlldata } from '../model';
16+
import {
17+
reloadFastGPTConfigBuffer,
18+
updateFastGPTConfigBuffer
19+
} from '../../../common/system/config/controller';
20+
import { delay } from '@fastgpt/global/common/system/utils';
1621

1722
/*
1823
TODO: 分优先级读取:
@@ -170,8 +175,21 @@ export const watchSystemModelUpdate = () => {
170175
'change',
171176
debounce(async () => {
172177
try {
178+
// Main node will reload twice
173179
await loadSystemModels(true);
180+
// All node reaload buffer
181+
await reloadFastGPTConfigBuffer();
174182
} catch (error) {}
175183
}, 500)
176184
);
177185
};
186+
187+
// 更新完模型后,需要重载缓存
188+
export const updatedReloadSystemModel = async () => {
189+
// 1. 更新模型(所有节点都会触发)
190+
await loadSystemModels(true);
191+
// 2. 更新缓存(仅主节点触发)
192+
await updateFastGPTConfigBuffer();
193+
// 3. 延迟1秒,等待其他节点刷新
194+
await delay(1000);
195+
};

Diff for: projects/app/src/components/core/app/TTSSelect.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ const TTSSelect = ({
7070
const provider = selectorList.find((item) => item.value === formatValue[0]) || selectorList[0];
7171
const voice = provider.children.find((item) => item.value === formatValue[1]);
7272
return (
73-
<Box minW={'150px'} maxW={'220px'} className="textEllipsis">
73+
<Box maxW={'220px'} className="textEllipsis">
7474
{voice ? (
7575
<Flex alignItems={'center'}>
7676
<Box>{provider.label}</Box>
@@ -141,7 +141,7 @@ const TTSSelect = ({
141141
<FormLabel>{t('common:core.app.tts.Speech model')}</FormLabel>
142142
<MultipleRowSelect
143143
rowMinWidth="160px"
144-
label={formLabel}
144+
label={<Box minW={'150px'}>{formLabel}</Box>}
145145
value={formatValue}
146146
list={selectorList}
147147
onSelect={onclickChange}

Diff for: projects/app/src/pages/api/core/ai/model/delete.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { MongoSystemModel } from '@fastgpt/service/core/ai/config/schema';
44
import { authSystemAdmin } from '@fastgpt/service/support/permission/user/auth';
55
import { findModelFromAlldata } from '@fastgpt/service/core/ai/model';
66
import { updateFastGPTConfigBuffer } from '@fastgpt/service/common/system/config/controller';
7-
import { loadSystemModels } from '@fastgpt/service/core/ai/config/utils';
7+
import { loadSystemModels, updatedReloadSystemModel } from '@fastgpt/service/core/ai/config/utils';
88

99
export type deleteQuery = {
1010
model: string;
@@ -34,8 +34,7 @@ async function handler(
3434

3535
await MongoSystemModel.deleteOne({ model });
3636

37-
await loadSystemModels(true);
38-
await updateFastGPTConfigBuffer();
37+
await updatedReloadSystemModel();
3938

4039
return {};
4140
}

Diff for: projects/app/src/pages/api/core/ai/model/update.ts

+2-5
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@ import type { ApiRequestProps, ApiResponseType } from '@fastgpt/service/type/nex
22
import { NextAPI } from '@/service/middleware/entry';
33
import { authSystemAdmin } from '@fastgpt/service/support/permission/user/auth';
44
import { MongoSystemModel } from '@fastgpt/service/core/ai/config/schema';
5-
import { delay } from '@fastgpt/global/common/system/utils';
6-
import { updateFastGPTConfigBuffer } from '@fastgpt/service/common/system/config/controller';
75
import { findModelFromAlldata } from '@fastgpt/service/core/ai/model';
8-
import { loadSystemModels } from '@fastgpt/service/core/ai/config/utils';
6+
import { updatedReloadSystemModel } from '@fastgpt/service/core/ai/config/utils';
97

108
export type updateQuery = {};
119

@@ -58,8 +56,7 @@ async function handler(
5856
}
5957
);
6058

61-
await loadSystemModels(true);
62-
await updateFastGPTConfigBuffer();
59+
await updatedReloadSystemModel();
6360

6461
return {};
6562
}

Diff for: projects/app/src/pages/api/core/ai/model/updateDefault.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { ApiRequestProps, ApiResponseType } from '@fastgpt/service/type/nex
22
import { NextAPI } from '@/service/middleware/entry';
33
import { mongoSessionRun } from '@fastgpt/service/common/mongo/sessionRun';
44
import { MongoSystemModel } from '@fastgpt/service/core/ai/config/schema';
5-
import { loadSystemModels } from '@fastgpt/service/core/ai/config/utils';
5+
import { loadSystemModels, updatedReloadSystemModel } from '@fastgpt/service/core/ai/config/utils';
66
import { updateFastGPTConfigBuffer } from '@fastgpt/service/common/system/config/controller';
77
import { ModelTypeEnum } from '@fastgpt/global/core/ai/model';
88
import { authSystemAdmin } from '@fastgpt/service/support/permission/user/auth';
@@ -67,8 +67,7 @@ async function handler(
6767
}
6868
});
6969

70-
await loadSystemModels(true);
71-
await updateFastGPTConfigBuffer();
70+
await updatedReloadSystemModel();
7271

7372
return {};
7473
}

Diff for: projects/app/src/pages/api/core/ai/model/updateWithJson.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ import { SystemModelSchemaType } from '@fastgpt/service/core/ai/type';
44
import { authSystemAdmin } from '@fastgpt/service/support/permission/user/auth';
55
import { mongoSessionRun } from '@fastgpt/service/common/mongo/sessionRun';
66
import { MongoSystemModel } from '@fastgpt/service/core/ai/config/schema';
7-
import { updateFastGPTConfigBuffer } from '@fastgpt/service/common/system/config/controller';
8-
import { loadSystemModels } from '@fastgpt/service/core/ai/config/utils';
7+
import { updatedReloadSystemModel } from '@fastgpt/service/core/ai/config/utils';
98

109
export type updateWithJsonQuery = {};
1110

@@ -55,8 +54,7 @@ async function handler(
5554
}
5655
});
5756

58-
await loadSystemModels(true);
59-
await updateFastGPTConfigBuffer();
57+
await updatedReloadSystemModel();
6058

6159
return {};
6260
}

0 commit comments

Comments
 (0)