Change sequential requests to parallel. (#909)
Parallel get label.json files. Atomic update tagCount.
This commit is contained in:
Родитель
e445dccfcb
Коммит
99b589201d
|
@ -171,7 +171,7 @@ export default class LocalFileSystem implements IStorageProvider {
|
|||
folderPath = [folderPath, folderName].join("/");
|
||||
const result: IAsset[] = [];
|
||||
const files = await this.listFiles(path.normalize(folderPath));
|
||||
for (const file of files) {
|
||||
await Promise.all(files.map(async (file) => {
|
||||
const fileParts = file.split(/[\\\/]/);
|
||||
const fileName = fileParts[fileParts.length - 1];
|
||||
const asset = await AssetService.createAssetFromFilePath(file, folderName + "/" + fileName, true);
|
||||
|
@ -191,11 +191,9 @@ export default class LocalFileSystem implements IStorageProvider {
|
|||
} else {
|
||||
asset.state = AssetState.NotVisited;
|
||||
}
|
||||
|
||||
result.push(asset);
|
||||
}
|
||||
}
|
||||
|
||||
}));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -205,7 +205,7 @@ export class AzureBlobStorage implements IStorageProvider {
|
|||
public async getAssets(folderPath?: string, folderName?: string): Promise<IAsset[]> {
|
||||
const files: string[] = await this.listFiles(folderPath);
|
||||
const result: IAsset[] = [];
|
||||
for (const file of files) {
|
||||
await Promise.all(files.map(async (file) => {
|
||||
const url = this.getUrl(file);
|
||||
const asset = await AssetService.createAssetFromFilePath(url, this.getFileName(url));
|
||||
if (this.isSupportedAssetType(asset.type)) {
|
||||
|
@ -228,7 +228,7 @@ export class AzureBlobStorage implements IStorageProvider {
|
|||
}
|
||||
result.push(asset);
|
||||
}
|
||||
}
|
||||
}));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -259,7 +259,7 @@ export default class ProjectService implements IProjectService {
|
|||
try {
|
||||
const blobs = new Set<string>(await storageProvider.listFiles(project.folderPath));
|
||||
const assetLabel = asset ? asset + constants.labelFileExtension : undefined;
|
||||
for (const blob of blobs) {
|
||||
await Promise.all(Array.from(blobs).map(async (blob) => {
|
||||
const blobFolderPath = blob.substr(0, blob.lastIndexOf("/"));
|
||||
if (blobFolderPath === project.folderPath
|
||||
&& blob.endsWith(constants.labelFileExtension)
|
||||
|
@ -267,6 +267,7 @@ export default class ProjectService implements IProjectService {
|
|||
try {
|
||||
if (!assetLabel || assetLabel === blob) {
|
||||
const content = JSON.parse(await storageProvider.readText(blob)) as ILabelData;
|
||||
const localTagDocumentCount = {};
|
||||
content.labels.forEach((label) => {
|
||||
if (constants.supportedLabelsSchemas.has(content?.$schema) && label.label.split("/").length > 1) {
|
||||
return;
|
||||
|
@ -277,22 +278,32 @@ export default class ProjectService implements IProjectService {
|
|||
} else {
|
||||
labelName = label.label
|
||||
}
|
||||
tagNameSet.add(labelName);
|
||||
if (tagDocumentCount[labelName]) {
|
||||
tagDocumentCount[labelName] += 1;
|
||||
if (localTagDocumentCount[labelName]) {
|
||||
localTagDocumentCount[labelName] += 1;
|
||||
} else {
|
||||
tagDocumentCount[labelName] = 1;
|
||||
localTagDocumentCount[labelName] = 1;
|
||||
}
|
||||
});
|
||||
}
|
||||
if (assetLabel && assetLabel === blob) {
|
||||
break;
|
||||
return localTagDocumentCount;
|
||||
}
|
||||
} catch (err) {
|
||||
// ignore err
|
||||
}
|
||||
}
|
||||
}
|
||||
})).then(localTagDocumentCounts => {
|
||||
for (const localTagDocumentCount of localTagDocumentCounts) {
|
||||
if (_.isPlainObject(localTagDocumentCount)) {
|
||||
for (const [labelName, labelCount] of Object.entries(localTagDocumentCount)) {
|
||||
tagNameSet.add(labelName);
|
||||
if (tagDocumentCount[labelName]) {
|
||||
tagDocumentCount[labelName] += labelCount;
|
||||
} else {
|
||||
tagDocumentCount[labelName] = labelCount;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
const tagNameArray = Array.from(tagNameSet);
|
||||
if (tagNameArray.containsDuplicates((name) => name)) {
|
||||
const reason = interpolate(
|
||||
|
|
Загрузка…
Ссылка в новой задаче