Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { DiaBackendAssetDownloadingService } from '../downloading/dia-backend-do
providedIn: 'root',
})
export class DiaBackendAssetPrefetchingService {
private readonly batchSize = 5;

constructor(
private readonly assetRepository: DiaBackendAssetRepository,
private readonly downloadingService: DiaBackendAssetDownloadingService,
Expand All @@ -32,19 +34,22 @@ export class DiaBackendAssetPrefetchingService {
if (diaBackendAssets.length === 0) {
break;
}
await Promise.all(
diaBackendAssets.map(async diaBackendAsset => {
if (diaBackendAsset.source_transaction === null)
await this.downloadingService.storeRemoteCapture(
diaBackendAsset,
(await this.mediaStore.getThumbnail(
diaBackendAsset.proof_hash
)) === undefined
);
currentCount += 1;
onStored(currentCount, totalCount);
})
);
for (let i = 0; i < diaBackendAssets.length; i += this.batchSize) {
const batch = diaBackendAssets.slice(i, i + this.batchSize);
await Promise.all(
batch.map(async diaBackendAsset => {
if (diaBackendAsset.source_transaction === null)
await this.downloadingService.storeRemoteCapture(
diaBackendAsset,
(await this.mediaStore.getThumbnail(
diaBackendAsset.proof_hash
)) === undefined
);
})
);
currentCount += batch.length;
onStored(currentCount, totalCount);
}
currentOffset += diaBackendAssets.length;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
import { HttpClient, HttpParams } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { BehaviorSubject, combineLatest, defer, forkJoin, Subject } from 'rxjs';
import {
BehaviorSubject,
EMPTY,
combineLatest,
defer,
forkJoin,
Subject,
} from 'rxjs';
import {
catchError,
concatMap,
distinctUntilChanged,
first,
Expand Down Expand Up @@ -86,7 +94,12 @@ export class DiaBackendTransactionRepository {
this.assetDownloadingService.storeRemoteCapture(asset)
)
)
)
),
catchError((err: unknown) => {
// eslint-disable-next-line no-console
console.error('downloadExpired$ error:', err);
return EMPTY;
})
);

constructor(
Expand Down
20 changes: 13 additions & 7 deletions src/app/shared/media/media-store/media-store.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,14 +265,20 @@ export class MediaStore {
* directly when dealing with small image for better performance.
*/
async getUrl(index: string, mimeType: MimeType) {
if (Capacitor.isNativePlatform()) {
// Workaround to fix urls (thumbnails) saved as incorrect mimeType.
await this.fixIncorrectExtension(index, mimeType);
return Capacitor.convertFileSrc(await this.getUri(index));
try {
if (Capacitor.isNativePlatform()) {
// Workaround to fix urls (thumbnails) saved as incorrect mimeType.
await this.fixIncorrectExtension(index, mimeType);
return Capacitor.convertFileSrc(await this.getUri(index));
}
return URL.createObjectURL(
await base64ToBlob(await this.readWithFileSystem(index), mimeType)
);
} catch (err: unknown) {
// eslint-disable-next-line no-console
console.error(`MediaStore.getUrl failed for index ${index}:`, err);
return '';
}
return URL.createObjectURL(
await base64ToBlob(await this.readWithFileSystem(index), mimeType)
);
}

private async fixIncorrectExtension(
Expand Down
Loading