Skip to content

Commit

Permalink
4818-alpha
Browse files Browse the repository at this point in the history
  • Loading branch information
c121914yu committed Jan 10, 2025
1 parent 041a899 commit d613214
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 20 deletions.
7 changes: 2 additions & 5 deletions packages/service/core/dataset/data/schema.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { connectionMongo, getMongoModel, type Model } from '../../../common/mongo';
import { connectionMongo, getMongoModel } from '../../../common/mongo';
const { Schema, model, models } = connectionMongo;
import { DatasetDataSchemaType } from '@fastgpt/global/core/dataset/type.d';
import {
Expand Down Expand Up @@ -70,10 +70,7 @@ const DatasetDataSchema = new Schema({
rebuilding: Boolean,

// Abandon
fullTextToken: {
type: String,
default: ''
},
fullTextToken: String,
initFullText: Boolean
});

Expand Down
18 changes: 3 additions & 15 deletions projects/app/src/pages/api/admin/initv4818.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
console.log('Init data time:', Date.now() - start);

success = 0;
await batchUpdateFields();
batchUpdateFields();

return { success: true };
}
Expand Down Expand Up @@ -84,8 +84,7 @@ const initData = async (batchSize: number) => {
// FullText tmp 把成功插入的新数据的 dataId 更新为已初始化
await MongoDatasetData.updateMany(
{ _id: { $in: result.map((item) => item.dataId) } },
{ $set: { initFullText: true }, $unset: { fullTextToken: 1 } },
// { $set: { initFullText: true } },
{ $set: { initFullText: true } },
{ session }
);

Expand All @@ -102,25 +101,14 @@ const initData = async (batchSize: number) => {
};

const batchUpdateFields = async (batchSize = 2000) => {
// Find documents that still have these fields
const documents = await MongoDatasetData.find({ initFullText: { $exists: true } }, '_id')
.limit(batchSize)
.lean();

if (documents.length === 0) return;

// Update in batches
await MongoDatasetData.updateMany(
{ _id: { $in: documents.map((doc) => doc._id) } },
{ initFullText: { $exists: true } },
{
$unset: {
initFullText: 1,
fullTextToken: 1
}
}
);

success += documents.length;
console.log('Delete success:', success);
await batchUpdateFields(batchSize);
};

0 comments on commit d613214

Please sign in to comment.