forked from Cutlery/immich
fix test
This commit is contained in:
parent
6f3401343f
commit
e6c761894c
@ -169,13 +169,15 @@ describe(LibraryService.name, () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('handleQueueAssetRefresh', () => {
|
describe('handleQueueAssetRefresh', () => {
|
||||||
it('should queue new assets', async () => {
|
it('should queue refresh of a new asset', async () => {
|
||||||
const mockLibraryJob: ILibraryRefreshJob = {
|
const mockLibraryJob: ILibraryRefreshJob = {
|
||||||
id: libraryStub.externalLibrary1.id,
|
id: libraryStub.externalLibrary1.id,
|
||||||
refreshModifiedFiles: false,
|
refreshModifiedFiles: false,
|
||||||
refreshAllFiles: false,
|
refreshAllFiles: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
assetMock.getWith.mockResolvedValue({ items: [], hasNextPage: false });
|
||||||
|
|
||||||
libraryMock.get.mockResolvedValue(libraryStub.externalLibrary1);
|
libraryMock.get.mockResolvedValue(libraryStub.externalLibrary1);
|
||||||
// eslint-disable-next-line @typescript-eslint/require-await
|
// eslint-disable-next-line @typescript-eslint/require-await
|
||||||
storageMock.walk.mockImplementation(async function* generator() {
|
storageMock.walk.mockImplementation(async function* generator() {
|
||||||
@ -205,6 +207,7 @@ describe(LibraryService.name, () => {
|
|||||||
refreshAllFiles: true,
|
refreshAllFiles: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
assetMock.getWith.mockResolvedValue({ items: [], hasNextPage: false });
|
||||||
libraryMock.get.mockResolvedValue(libraryStub.externalLibrary1);
|
libraryMock.get.mockResolvedValue(libraryStub.externalLibrary1);
|
||||||
// eslint-disable-next-line @typescript-eslint/require-await
|
// eslint-disable-next-line @typescript-eslint/require-await
|
||||||
storageMock.walk.mockImplementation(async function* generator() {
|
storageMock.walk.mockImplementation(async function* generator() {
|
||||||
|
@ -643,15 +643,12 @@ export class LibraryService extends EventEmitter {
|
|||||||
this.assetRepository.getWith(pagination, WithProperty.IS_ONLINE, job.id),
|
this.assetRepository.getWith(pagination, WithProperty.IS_ONLINE, job.id),
|
||||||
);
|
);
|
||||||
|
|
||||||
let crawledAssetPaths: string[] = [];
|
|
||||||
|
|
||||||
let crawlCounter = 0;
|
|
||||||
let crawlDone = false;
|
let crawlDone = false;
|
||||||
let existingAssetsDone = false;
|
let existingAssetsDone = false;
|
||||||
|
let crawlCounter = 0;
|
||||||
let existingAssetCounter = 0;
|
let existingAssetCounter = 0;
|
||||||
|
|
||||||
const scanNextAssetPage = async () => {
|
const checkNextAssetPageForOffline = async () => {
|
||||||
if (!existingAssetsDone) {
|
|
||||||
const existingAssetPage = await existingAssets.next();
|
const existingAssetPage = await existingAssets.next();
|
||||||
existingAssetsDone = existingAssetPage.done ?? true;
|
existingAssetsDone = existingAssetPage.done ?? true;
|
||||||
|
|
||||||
@ -667,16 +664,19 @@ export class LibraryService extends EventEmitter {
|
|||||||
})),
|
})),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let crawledAssetPaths: string[] = [];
|
||||||
|
|
||||||
while (!crawlDone) {
|
while (!crawlDone) {
|
||||||
const crawlResult = await crawledAssets.next();
|
const crawlResult = await crawledAssets.next();
|
||||||
|
|
||||||
crawlDone = crawlResult.done ?? true;
|
crawlDone = crawlResult.done ?? true;
|
||||||
|
|
||||||
|
if (!crawlDone) {
|
||||||
crawledAssetPaths.push(crawlResult.value);
|
crawledAssetPaths.push(crawlResult.value);
|
||||||
crawlCounter++;
|
crawlCounter++;
|
||||||
|
}
|
||||||
|
|
||||||
if (crawledAssetPaths.length % LIBRARY_SCAN_BATCH_SIZE === 0 || crawlDone) {
|
if (crawledAssetPaths.length % LIBRARY_SCAN_BATCH_SIZE === 0 || crawlDone) {
|
||||||
this.logger.log(`Queueing scan of ${crawledAssetPaths.length} asset path(s) in library ${library.id}...`);
|
this.logger.log(`Queueing scan of ${crawledAssetPaths.length} asset path(s) in library ${library.id}...`);
|
||||||
@ -684,14 +684,16 @@ export class LibraryService extends EventEmitter {
|
|||||||
await this.scanAssets(job.id, crawledAssetPaths, library.ownerId, job.refreshAllFiles ?? false);
|
await this.scanAssets(job.id, crawledAssetPaths, library.ownerId, job.refreshAllFiles ?? false);
|
||||||
crawledAssetPaths = [];
|
crawledAssetPaths = [];
|
||||||
|
|
||||||
|
if (!existingAssetsDone) {
|
||||||
// Interweave the queuing of offline checks with the asset scanning (if any)
|
// Interweave the queuing of offline checks with the asset scanning (if any)
|
||||||
await scanNextAssetPage();
|
await checkNextAssetPageForOffline();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If there are any remaining assets to check for offline status, do so
|
// If there are any remaining assets to check for offline status, do so
|
||||||
while (!existingAssetsDone) {
|
while (!existingAssetsDone) {
|
||||||
await scanNextAssetPage();
|
await checkNextAssetPageForOffline();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.logger.log(
|
this.logger.log(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user