mirror of
https://github.com/immich-app/immich.git
synced 2025-11-03 09:42:45 +09:00
fix(cli): Concurrency not fully using queue potential (#11828)
Some checks failed
Test / Unit Test CLI (Windows) (push) Blocked by required conditions
Test / Medium Tests (Server) (push) Blocked by required conditions
Test / End-to-End Tests (Server & CLI) (push) Blocked by required conditions
Test / End-to-End Tests (Web) (push) Blocked by required conditions
CLI Build / CLI Publish (push) Successful in 36s
CodeQL / Analyze (javascript) (push) Failing after 1m51s
CodeQL / Analyze (python) (push) Failing after 25s
Docker / pre-job (push) Successful in 8s
Docs build / pre-job (push) Successful in 5s
Static Code Analysis / pre-job (push) Successful in 6s
Test / pre-job (push) Successful in 6s
Test / ShellCheck (push) Successful in 9s
Test / OpenAPI Clients (push) Failing after 2m24s
Test / TypeORM Checks (push) Failing after 13s
CLI Build / Docker (push) Failing after 1m12s
Docker / Re-Tag ML () (push) Failing after 4s
Docker / Re-Tag ML (-armnn) (push) Failing after 4s
Docker / Re-Tag ML (-cuda) (push) Failing after 4s
Docker / Re-Tag ML (-openvino) (push) Failing after 5s
Docker / Re-Tag Server () (push) Failing after 4s
Docker / Build and Push ML (armnn, linux/arm64, -armnn) (push) Has been skipped
Docker / Build and Push ML (cpu, linux/amd64,linux/arm64) (push) Has been skipped
Docker / Build and Push ML (cuda, linux/amd64, -cuda) (push) Has been skipped
Docker / Build and Push ML (openvino, linux/amd64, -openvino) (push) Has been skipped
Docker / Build and Push Server (cpu, linux/amd64,linux/arm64) (push) Has been skipped
Docs build / Docs Build (push) Failing after 3m45s
Static Code Analysis / Run Dart Code Analysis (push) Has been skipped
Test / Test & Lint Server (push) Has been skipped
Test / Unit Test CLI (push) Successful in 18s
Test / Test & Lint Web (push) Has been skipped
Test / End-to-End Lint (push) Successful in 21s
Test / Unit Test Mobile (push) Has been skipped
Test / Unit Test ML (push) Has been skipped
Docker / Docker Build & Push ML Success (push) Successful in 2s
Docker / Docker Build & Push Server Success (push) Successful in 2s
Some checks failed
Test / Unit Test CLI (Windows) (push) Blocked by required conditions
Test / Medium Tests (Server) (push) Blocked by required conditions
Test / End-to-End Tests (Server & CLI) (push) Blocked by required conditions
Test / End-to-End Tests (Web) (push) Blocked by required conditions
CLI Build / CLI Publish (push) Successful in 36s
CodeQL / Analyze (javascript) (push) Failing after 1m51s
CodeQL / Analyze (python) (push) Failing after 25s
Docker / pre-job (push) Successful in 8s
Docs build / pre-job (push) Successful in 5s
Static Code Analysis / pre-job (push) Successful in 6s
Test / pre-job (push) Successful in 6s
Test / ShellCheck (push) Successful in 9s
Test / OpenAPI Clients (push) Failing after 2m24s
Test / TypeORM Checks (push) Failing after 13s
CLI Build / Docker (push) Failing after 1m12s
Docker / Re-Tag ML () (push) Failing after 4s
Docker / Re-Tag ML (-armnn) (push) Failing after 4s
Docker / Re-Tag ML (-cuda) (push) Failing after 4s
Docker / Re-Tag ML (-openvino) (push) Failing after 5s
Docker / Re-Tag Server () (push) Failing after 4s
Docker / Build and Push ML (armnn, linux/arm64, -armnn) (push) Has been skipped
Docker / Build and Push ML (cpu, linux/amd64,linux/arm64) (push) Has been skipped
Docker / Build and Push ML (cuda, linux/amd64, -cuda) (push) Has been skipped
Docker / Build and Push ML (openvino, linux/amd64, -openvino) (push) Has been skipped
Docker / Build and Push Server (cpu, linux/amd64,linux/arm64) (push) Has been skipped
Docs build / Docs Build (push) Failing after 3m45s
Static Code Analysis / Run Dart Code Analysis (push) Has been skipped
Test / Test & Lint Server (push) Has been skipped
Test / Unit Test CLI (push) Successful in 18s
Test / Test & Lint Web (push) Has been skipped
Test / End-to-End Lint (push) Successful in 21s
Test / Unit Test Mobile (push) Has been skipped
Test / Unit Test ML (push) Has been skipped
Docker / Docker Build & Push ML Success (push) Successful in 2s
Docker / Docker Build & Push Server Success (push) Successful in 2s
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import {
|
||||
Action,
|
||||
AssetBulkUploadCheckItem,
|
||||
AssetBulkUploadCheckResult,
|
||||
AssetMediaResponseDto,
|
||||
AssetMediaStatus,
|
||||
@@ -11,7 +12,7 @@ import {
|
||||
getSupportedMediaTypes,
|
||||
} from '@immich/sdk';
|
||||
import byteSize from 'byte-size';
|
||||
import { Presets, SingleBar } from 'cli-progress';
|
||||
import { MultiBar, Presets, SingleBar } from 'cli-progress';
|
||||
import { chunk } from 'lodash-es';
|
||||
import { Stats, createReadStream } from 'node:fs';
|
||||
import { stat, unlink } from 'node:fs/promises';
|
||||
@@ -90,23 +91,23 @@ export const checkForDuplicates = async (files: string[], { concurrency, skipHas
|
||||
return { newFiles: files, duplicates: [] };
|
||||
}
|
||||
|
||||
const progressBar = new SingleBar(
|
||||
{ format: 'Checking files | {bar} | {percentage}% | ETA: {eta}s | {value}/{total} assets' },
|
||||
const multiBar = new MultiBar(
|
||||
{ format: '{message} | {bar} | {percentage}% | ETA: {eta}s | {value}/{total} assets' },
|
||||
Presets.shades_classic,
|
||||
);
|
||||
|
||||
progressBar.start(files.length, 0);
|
||||
const hashProgressBar = multiBar.create(files.length, 0, { message: 'Hashing files ' });
|
||||
const checkProgressBar = multiBar.create(files.length, 0, { message: 'Checking for duplicates' });
|
||||
|
||||
const newFiles: string[] = [];
|
||||
const duplicates: Asset[] = [];
|
||||
|
||||
const queue = new Queue<string[], AssetBulkUploadCheckResults>(
|
||||
async (filepaths: string[]) => {
|
||||
const dto = await Promise.all(
|
||||
filepaths.map(async (filepath) => ({ id: filepath, checksum: await sha1(filepath) })),
|
||||
);
|
||||
const response = await checkBulkUpload({ assetBulkUploadCheckDto: { assets: dto } });
|
||||
const checkBulkUploadQueue = new Queue<AssetBulkUploadCheckItem[], void>(
|
||||
async (assets: AssetBulkUploadCheckItem[]) => {
|
||||
const response = await checkBulkUpload({ assetBulkUploadCheckDto: { assets } });
|
||||
|
||||
const results = response.results as AssetBulkUploadCheckResults;
|
||||
|
||||
for (const { id: filepath, assetId, action } of results) {
|
||||
if (action === Action.Accept) {
|
||||
newFiles.push(filepath);
|
||||
@@ -115,19 +116,46 @@ export const checkForDuplicates = async (files: string[], { concurrency, skipHas
|
||||
duplicates.push({ id: assetId as string, filepath });
|
||||
}
|
||||
}
|
||||
progressBar.increment(filepaths.length);
|
||||
|
||||
checkProgressBar.increment(assets.length);
|
||||
},
|
||||
{ concurrency, retry: 3 },
|
||||
);
|
||||
|
||||
const results: { id: string; checksum: string }[] = [];
|
||||
let checkBulkUploadRequests: AssetBulkUploadCheckItem[] = [];
|
||||
|
||||
const queue = new Queue<string, AssetBulkUploadCheckItem[]>(
|
||||
async (filepath: string): Promise<AssetBulkUploadCheckItem[]> => {
|
||||
const dto = { id: filepath, checksum: await sha1(filepath) };
|
||||
|
||||
results.push(dto);
|
||||
checkBulkUploadRequests.push(dto);
|
||||
if (checkBulkUploadRequests.length === 5000) {
|
||||
const batch = checkBulkUploadRequests;
|
||||
checkBulkUploadRequests = [];
|
||||
void checkBulkUploadQueue.push(batch);
|
||||
}
|
||||
|
||||
hashProgressBar.increment();
|
||||
return results;
|
||||
},
|
||||
{ concurrency, retry: 3 },
|
||||
);
|
||||
|
||||
for (const items of chunk(files, concurrency)) {
|
||||
await queue.push(items);
|
||||
for (const item of files) {
|
||||
void queue.push(item);
|
||||
}
|
||||
|
||||
await queue.drained();
|
||||
|
||||
progressBar.stop();
|
||||
if (checkBulkUploadRequests.length > 0) {
|
||||
void checkBulkUploadQueue.push(checkBulkUploadRequests);
|
||||
}
|
||||
|
||||
await checkBulkUploadQueue.drained();
|
||||
|
||||
multiBar.stop();
|
||||
|
||||
console.log(`Found ${newFiles.length} new files and ${duplicates.length} duplicate${s(duplicates.length)}`);
|
||||
|
||||
@@ -201,8 +229,8 @@ export const uploadFiles = async (files: string[], { dryRun, concurrency }: Uplo
|
||||
{ concurrency, retry: 3 },
|
||||
);
|
||||
|
||||
for (const filepath of files) {
|
||||
await queue.push(filepath);
|
||||
for (const item of files) {
|
||||
void queue.push(item);
|
||||
}
|
||||
|
||||
await queue.drained();
|
||||
|
||||
Reference in New Issue
Block a user