add in-memory cache
This commit is contained in:
parent
7c4e3bfacd
commit
5b7e818ca4
|
@ -67,6 +67,8 @@ export const ENTE_EXPORT_DIRECTORY = 'ente Photos';
|
||||||
|
|
||||||
class ExportService {
|
class ExportService {
|
||||||
private electronAPIs: ElectronAPIs;
|
private electronAPIs: ElectronAPIs;
|
||||||
|
private exportRecord: ExportRecord;
|
||||||
|
private exportSettings: ExportSettings;
|
||||||
private exportInProgress: boolean = false;
|
private exportInProgress: boolean = false;
|
||||||
private reRunNeeded = false;
|
private reRunNeeded = false;
|
||||||
private exportRecordUpdater = new QueueProcessor<ExportRecord>(1);
|
private exportRecordUpdater = new QueueProcessor<ExportRecord>(1);
|
||||||
|
@ -94,7 +96,9 @@ class ExportService {
|
||||||
|
|
||||||
getExportSettings(): ExportSettings {
|
getExportSettings(): ExportSettings {
|
||||||
try {
|
try {
|
||||||
|
if (this.exportSettings) return this.exportSettings;
|
||||||
const exportSettings = getData(LS_KEYS.EXPORT);
|
const exportSettings = getData(LS_KEYS.EXPORT);
|
||||||
|
this.exportSettings = exportSettings;
|
||||||
return exportSettings;
|
return exportSettings;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logError(e, 'getExportSettings failed');
|
logError(e, 'getExportSettings failed');
|
||||||
|
@ -106,6 +110,7 @@ class ExportService {
|
||||||
try {
|
try {
|
||||||
const exportSettings = this.getExportSettings();
|
const exportSettings = this.getExportSettings();
|
||||||
const newSettings = { ...exportSettings, ...newData };
|
const newSettings = { ...exportSettings, ...newData };
|
||||||
|
this.exportSettings = newSettings;
|
||||||
setData(LS_KEYS.EXPORT, newSettings);
|
setData(LS_KEYS.EXPORT, newSettings);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logError(e, 'updateExportSettings failed');
|
logError(e, 'updateExportSettings failed');
|
||||||
|
@ -852,11 +857,13 @@ class ExportService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
updateExportRecord(newData: Partial<ExportRecord>, folder?: string) {
|
async updateExportRecord(newData: Partial<ExportRecord>, folder?: string) {
|
||||||
const response = this.exportRecordUpdater.queueUpRequest(() =>
|
const response = this.exportRecordUpdater.queueUpRequest(() =>
|
||||||
this.updateExportRecordHelper(folder, newData)
|
this.updateExportRecordHelper(folder, newData)
|
||||||
);
|
);
|
||||||
return response.promise;
|
const updatedExportRecord = await response.promise;
|
||||||
|
this.exportRecord = updatedExportRecord;
|
||||||
|
return updatedExportRecord;
|
||||||
}
|
}
|
||||||
|
|
||||||
async updateExportRecordHelper(
|
async updateExportRecordHelper(
|
||||||
|
@ -882,6 +889,7 @@ class ExportService {
|
||||||
|
|
||||||
async getExportRecord(folder: string): Promise<ExportRecord> {
|
async getExportRecord(folder: string): Promise<ExportRecord> {
|
||||||
try {
|
try {
|
||||||
|
if (this.exportRecord) return this.exportRecord;
|
||||||
if (!folder || !this.exists(folder)) {
|
if (!folder || !this.exists(folder)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue