Skip to content

Commit

Permalink
Merge pull request #232 from xtreme1-io/fix-largeurl
Browse files Browse the repository at this point in the history
fix: pc-tool large url
  • Loading branch information
jaggerwang authored Apr 12, 2024
2 parents c9b7d6b + 858c5d8 commit ec6085a
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 11 deletions.
58 changes: 49 additions & 9 deletions frontend/pc-tool/src/api/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,26 @@ export async function saveObject(config: any) {
return keyMap;
}

export async function getDataObjectBatch(dataIds: string[] | string) {
if (!Array.isArray(dataIds)) dataIds = [dataIds];
const batchSize = 200;
const requests: ReturnType<typeof getDataObject>[] = [];
while (dataIds.length > 0) {
const batchIds = dataIds.splice(0, batchSize);
requests.push(getDataObject(batchIds));
}
return Promise.all(requests).then((res) => {
return res.reduce(
(map, item) => {
Object.assign(map.objectsMap, item.objectsMap || {});
Object.assign(map.classificationMap, item.classificationMap || {});
return map;
},
{ objectsMap: {}, classificationMap: {}, queryTime: Date.now() },
);
});
}

export async function getDataObject(dataIds: string[] | string) {
if (!Array.isArray(dataIds)) dataIds = [dataIds];

Expand Down Expand Up @@ -84,22 +104,43 @@ export async function getDataClassification(dataIds: string[] | string) {
});
return attrsMap;
}

export async function getDataClassificationBatch(dataIds: string[] | string) {
if (!Array.isArray(dataIds)) dataIds = [dataIds];
const batchSize = 200;
const requests: Promise<any>[] = [];
while (dataIds.length > 0) {
const batchIds = dataIds.splice(0, batchSize);
requests.push(getDataClassification(batchIds));
}
return Promise.all(requests).then((res) => {
return res.reduce((map, item) => {
return Object.assign(map, item);
}, {});
});
}
export async function unlockRecord(recordId: string) {
let url = `/api/data/unLock/${recordId}`;
return await post(url);
}

export async function getDataStatus(dataIds: string[]) {
const batchSize = 200;
const requests: Promise<any>[] = [];
let url = '/api/data/getDataStatusByIds';
let argsStr = queryStr({ dataIds });
let data = await get(`${url}?${argsStr}`);

let statusMap = {};
data.data.forEach((e: any) => {
statusMap[e.id] = e;
while (dataIds.length > 0) {
const batchIds = dataIds.splice(0, batchSize);
let argsStr = queryStr({ dataIds: batchIds });
requests.push(get(`${url}?${argsStr}`));
}
return Promise.all(requests).then((res) => {
const statusMap = {};
res.forEach((re) => {
re.data.forEach((item: any) => {
statusMap[item.id] = item;
});
});
return statusMap;
});
return statusMap;
}

export async function getInfoByRecordId(recordId: string) {
Expand Down Expand Up @@ -146,7 +187,6 @@ export async function getInfoByRecordId(recordId: string) {

let ids = dataInfos.map((e) => e.id);
let stateMap = await getDataStatus(ids);

dataInfos.forEach((data) => {
let status = stateMap[data.id];
if (!status) return;
Expand Down
4 changes: 2 additions & 2 deletions frontend/pc-tool/src/common/BusinessManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export default class BusinessManager extends BaseBusinessManager {
async getFrameClassification(
frame: IFrame | IFrame[],
): Promise<Record<string, Record<string, string>>> {
let valueMap = await api.getDataClassification(
let valueMap = await api.getDataClassificationBatch(
Array.isArray(frame) ? frame.map((e) => e.id) : frame.id,
);
return valueMap;
Expand All @@ -59,7 +59,7 @@ export default class BusinessManager extends BaseBusinessManager {
classificationMap: Record<string, IObject[]>;
queryTime: string;
}> {
let data = await api.getDataObject(
let data = await api.getDataObjectBatch(
Array.isArray(frame) ? frame.map((e) => e.id) : frame.id,
);
return data;
Expand Down

0 comments on commit ec6085a

Please sign in to comment.