1
0
forked from Cutlery/immich
This commit is contained in:
Jonathan Jogenfors 2024-03-19 22:39:35 +01:00
parent 6f3401343f
commit e6c761894c
2 changed files with 30 additions and 25 deletions

View File

@ -169,13 +169,15 @@ describe(LibraryService.name, () => {
});
describe('handleQueueAssetRefresh', () => {
it('should queue new assets', async () => {
it('should queue refresh of a new asset', async () => {
const mockLibraryJob: ILibraryRefreshJob = {
id: libraryStub.externalLibrary1.id,
refreshModifiedFiles: false,
refreshAllFiles: false,
};
assetMock.getWith.mockResolvedValue({ items: [], hasNextPage: false });
libraryMock.get.mockResolvedValue(libraryStub.externalLibrary1);
// eslint-disable-next-line @typescript-eslint/require-await
storageMock.walk.mockImplementation(async function* generator() {
@ -205,6 +207,7 @@ describe(LibraryService.name, () => {
refreshAllFiles: true,
};
assetMock.getWith.mockResolvedValue({ items: [], hasNextPage: false });
libraryMock.get.mockResolvedValue(libraryStub.externalLibrary1);
// eslint-disable-next-line @typescript-eslint/require-await
storageMock.walk.mockImplementation(async function* generator() {

View File

@ -643,15 +643,12 @@ export class LibraryService extends EventEmitter {
this.assetRepository.getWith(pagination, WithProperty.IS_ONLINE, job.id),
);
let crawledAssetPaths: string[] = [];
let crawlCounter = 0;
let crawlDone = false;
let existingAssetsDone = false;
let crawlCounter = 0;
let existingAssetCounter = 0;
const scanNextAssetPage = async () => {
if (!existingAssetsDone) {
const checkNextAssetPageForOffline = async () => {
const existingAssetPage = await existingAssets.next();
existingAssetsDone = existingAssetPage.done ?? true;
@ -667,16 +664,19 @@ export class LibraryService extends EventEmitter {
})),
);
}
}
};
let crawledAssetPaths: string[] = [];
while (!crawlDone) {
const crawlResult = await crawledAssets.next();
crawlDone = crawlResult.done ?? true;
if (!crawlDone) {
crawledAssetPaths.push(crawlResult.value);
crawlCounter++;
}
if (crawledAssetPaths.length % LIBRARY_SCAN_BATCH_SIZE === 0 || crawlDone) {
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);
crawledAssetPaths = [];
if (!existingAssetsDone) {
// 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
while (!existingAssetsDone) {
await scanNextAssetPage();
await checkNextAssetPageForOffline();
}
this.logger.log(