Skip to content

Commit

Permalink
fix: 46 tmbId empty (#480)
Browse files Browse the repository at this point in the history
* mongo init

* perf: mongo connect

* perf: favicon

* fix: member  id

* 46fix sh

* doc
  • Loading branch information
c121914yu authored Nov 16, 2023
1 parent fbe1d8c commit f6aea48
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 32 deletions.
12 changes: 12 additions & 0 deletions docSite/content/docs/installation/upgrading/46.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,15 @@ curl --location --request POST 'https://{{host}}/api/admin/initv46-2' \
4. 新增 - 支持知识库配置文本预处理模型
5. 线上环境新增 - ReRank向量召回,提高召回精度
6. 优化 - 知识库导出,可直接触发流下载,无需等待转圈圈

## 4.6缺陷修复

旧的 4.6 版本由于缺少一个字段,导致文件导入时知识库数据无法显示,可执行下面的脚本:

https://xxxxx/api/admin/initv46-fix

```bash
curl --location --request POST 'https://{{host}}/api/admin/initv46-fix' \
--header 'rootkey: {{rootkey}}' \
--header 'Content-Type: application/json'
```
2 changes: 1 addition & 1 deletion projects/app/src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ function App({ Component, pageProps }: AppProps) {
name="viewport"
content="width=device-width,initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0,user-scalable=no, viewport-fit=cover"
/>
<link rel="icon" href={feConfigs.favicon || '/favicon.ico'} />
<link rel="icon" href={feConfigs.favicon || process.env.SYSTEM_FAVICON} />
</Head>
{scripts?.map((item, i) => <Script key={i} strategy="lazyOnload" {...item}></Script>)}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import {

import { authCert } from '@fastgpt/service/support/permission/auth/common';
import { MongoDatasetData } from '@fastgpt/service/core/dataset/data/schema';
import { Types, connectionMongo } from '@fastgpt/service/common/mongo';
import { TeamMemberCollectionName } from '@fastgpt/global/support/user/team/constant';

let success = 0;
/* pg 中的数据搬到 mongo dataset.datas 中,并做映射 */
Expand Down Expand Up @@ -43,57 +45,59 @@ type PgItemType = {
};

async function init(limit: number): Promise<any> {
const { rows: idList } = await PgClient.query<{ id: string }>(
`SELECT id FROM ${PgDatasetTableName} WHERE inited=1`
const { rows } = await PgClient.query<{ id: string; data_id: string }>(
`SELECT id,data_id FROM ${PgDatasetTableName} WHERE team_id = tmb_id`
);

console.log('totalCount', idList.length);
console.log('totalCount', rows.length);

await delay(2000);

if (idList.length === 0) return;
if (rows.length === 0) return;

for (let i = 0; i < limit; i++) {
initData(i);
}

async function initData(index: number): Promise<any> {
const dataId = idList[index]?.id;
if (!dataId) {
const item = rows[index];
if (!item) {
console.log('done');
return;
}
// get limit data where data_id is null
const { rows } = await PgClient.query<PgItemType>(
`SELECT id,q,a,dataset_id,collection_id,data_id FROM ${PgDatasetTableName} WHERE id=${dataId};`
);
const data = rows[0];
if (!data) {
console.log('done');
return;
// get mongo
const mongoData = await MongoDatasetData.findById(item.data_id, '_id teamId tmbId');
if (!mongoData) {
return initData(index + limit);
}

try {
// update mongo data and update inited
await MongoDatasetData.findByIdAndUpdate(data.data_id, {
q: data.q,
a: data.a,
indexes: [
{
defaultIndex: !data.a,
type: data.a ? DatasetDataIndexTypeEnum.qa : DatasetDataIndexTypeEnum.chunk,
dataId: data.id,
text: data.q
}
]
// find team owner
const db = connectionMongo?.connection?.db;
const TeamMember = db.collection(TeamMemberCollectionName);

const tmb = await TeamMember.findOne({
teamId: new Types.ObjectId(mongoData.teamId),
role: 'owner'
});
// update pg data_id
await PgClient.query(`UPDATE ${PgDatasetTableName} SET inited=0 WHERE id=${dataId};`);

if (!tmb) {
return initData(index + limit);
}

// update mongo and pg tmb_id
await MongoDatasetData.findByIdAndUpdate(item.data_id, {
tmbId: tmb._id
});
await PgClient.query(
`UPDATE ${PgDatasetTableName} SET tmb_id = '${String(tmb._id)}' WHERE id = '${item.id}'`
);

console.log(++success);

return initData(index + limit);
} catch (error) {
console.log(error);
console.log(data);
await delay(500);
return initData(index);
}
Expand Down
3 changes: 3 additions & 0 deletions projects/app/src/service/core/dataset/data/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ export async function insertData2Dataset({
if (!q || !datasetId || !collectionId || !model) {
return Promise.reject('q, datasetId, collectionId, model is required');
}
if (String(teamId) === String(tmbId)) {
return Promise.reject("teamId and tmbId can't be the same");
}

q = q.trim();
a = a.trim();
Expand Down
4 changes: 2 additions & 2 deletions projects/app/src/service/events/generateVector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export async function generateVector(): Promise<any> {
// insert data to pg
const { tokenLen } = await insertData2Dataset({
teamId: data.teamId,
tmbId: data.teamId,
tmbId: data.tmbId,
datasetId: data.datasetId,
collectionId: data.collectionId,
q: dataItem.q,
Expand All @@ -124,7 +124,7 @@ export async function generateVector(): Promise<any> {
// push bill
pushGenerateVectorBill({
teamId: data.teamId,
tmbId: data.teamId,
tmbId: data.tmbId,
tokenLen: tokenLen,
model: data.model,
billId: data.billId
Expand Down

0 comments on commit f6aea48

Please sign in to comment.