refactor export json migration

This commit is contained in:
Abhinav 2023-05-03 18:34:52 +05:30
parent 964e9da437
commit 6dc4b7b61e
2 changed files with 11 additions and 14 deletions

View file

@ -57,7 +57,7 @@ import {
getCollectionNameMap, getCollectionNameMap,
getNonEmptyPersonalCollections, getNonEmptyPersonalCollections,
} from 'utils/collection'; } from 'utils/collection';
import { migrateExportJSONHelper } from './migration'; import { migrateExportJSON } from './migration';
const EXPORT_RECORD_FILE_NAME = 'export_status.json'; const EXPORT_RECORD_FILE_NAME = 'export_status.json';
@ -78,7 +78,7 @@ class ExportService {
success: 0, success: 0,
failed: 0, failed: 0,
}; };
private exportJSONMigrator = new QueueProcessor<void>(1); private migrationInProgress: Promise<void>;
constructor() { constructor() {
if (runningInBrowser()) { if (runningInBrowser()) {
@ -88,16 +88,9 @@ class ExportService {
} }
} }
async migrateExportJSON() {
const response = this.exportJSONMigrator.queueUpRequest(() =>
migrateExportJSONHelper()
);
return response.promise;
}
async init(uiUpdater: ExportUIUpdaters) { async init(uiUpdater: ExportUIUpdaters) {
this.setUIUpdaters(uiUpdater); this.setUIUpdaters(uiUpdater);
await this.migrateExportJSON(); this.migrationInProgress = migrateExportJSON();
} }
async setUIUpdaters(uiUpdater: ExportUIUpdaters) { async setUIUpdaters(uiUpdater: ExportUIUpdaters) {
@ -212,7 +205,6 @@ class ExportService {
async preExport() { async preExport() {
this.stopExport = false; this.stopExport = false;
this.exportInProgress = true;
await this.uiUpdater.updateExportStage(ExportStage.INPROGRESS); await this.uiUpdater.updateExportStage(ExportStage.INPROGRESS);
this.updateExportProgress({ this.updateExportProgress({
success: 0, success: 0,
@ -239,15 +231,20 @@ class ExportService {
scheduleExport = async () => { scheduleExport = async () => {
try { try {
addLogLine('scheduling export');
if (this.exportInProgress) { if (this.exportInProgress) {
addLogLine('export in progress, scheduling re-run'); addLogLine('export in progress, scheduling re-run');
this.reRunNeeded = true; this.reRunNeeded = true;
return; return;
} }
this.exportInProgress = true;
if (this.migrationInProgress) {
addLogLine('migration in progress, waiting for it to complete');
await this.migrationInProgress;
this.migrationInProgress = null;
}
try { try {
await this.preExport(); await this.preExport();
// checking if migration is needed
await this.migrateExportJSON();
addLogLine('export started'); addLogLine('export started');
await this.runExport(); await this.runExport();
addLogLine('export completed'); addLogLine('export completed');

View file

@ -37,7 +37,7 @@ import { decodeLivePhoto } from 'services/livePhotoService';
import downloadManager from 'services/downloadManager'; import downloadManager from 'services/downloadManager';
import { retryAsyncFunction } from 'utils/network'; import { retryAsyncFunction } from 'utils/network';
export async function migrateExportJSONHelper() { export async function migrateExportJSON() {
try { try {
const exportDir = getData(LS_KEYS.EXPORT)?.folder; const exportDir = getData(LS_KEYS.EXPORT)?.folder;
if (!exportDir) { if (!exportDir) {