Skip to content

Commit 26cd254

Browse files
committed
feat: init script for website sync refactor
1 parent 2ccdd23 commit 26cd254

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { NextAPI } from '@/service/middleware/entry';
2+
import { getDatasetCollections } from '@/web/core/dataset/api';
3+
import { DatasetTypeEnum } from '@fastgpt/global/core/dataset/constants';
4+
import { mongoSessionRun } from '@fastgpt/service/common/mongo/sessionRun';
5+
import { MongoDatasetCollection } from '@fastgpt/service/core/dataset/collection/schema';
6+
import { MongoDataset } from '@fastgpt/service/core/dataset/schema';
7+
import { upsertWebsiteSyncJobScheduler } from '@fastgpt/service/core/dataset/websiteSync';
8+
import { authCert } from '@fastgpt/service/support/permission/auth/common';
9+
import { NextApiRequest, NextApiResponse } from 'next';
10+
11+
async function handler(req: NextApiRequest, _res: NextApiResponse) {
12+
await authCert({ req, authRoot: true });
13+
14+
await mongoSessionRun(async (session) => {
15+
// find out all website dataset
16+
const datasets = await MongoDataset.find({ type: DatasetTypeEnum.websiteDataset }, undefined, {
17+
session
18+
});
19+
20+
await Promise.all(
21+
datasets.flatMap((dataset) => {
22+
if (dataset.autoSync)
23+
return upsertWebsiteSyncJobScheduler({ datasetId: String(dataset._id) });
24+
else return [];
25+
})
26+
);
27+
28+
// clear all collection next sync time
29+
for (const dataset of datasets) {
30+
await MongoDatasetCollection.updateMany(
31+
{
32+
teamId: dataset.teamId,
33+
datasetId: dataset._id
34+
},
35+
{
36+
$unset: {
37+
nextSyncTime: 1
38+
}
39+
},
40+
{ session }
41+
);
42+
}
43+
});
44+
45+
return { success: true };
46+
}
47+
48+
export default NextAPI(handler);

projects/app/src/pages/api/core/dataset/update.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ const updateSyncSchedule = async ({
286286
{
287287
teamId: dataset.teamId,
288288
datasetId: dataset._id,
289-
type: { $in: [DatasetCollectionTypeEnum.apiFile] }
289+
type: { $in: [DatasetCollectionTypeEnum.apiFile, DatasetCollectionTypeEnum.link] }
290290
},
291291
{
292292
$set: {

0 commit comments

Comments
 (0)