feat: Ionic v6 breadcrumbs in catalog module

This commit is contained in:
Thea Schöbl
2022-04-13 14:10:16 +00:00
parent 552911cfcf
commit 7b491ed3bb
66 changed files with 653 additions and 199 deletions

View File

@@ -30,6 +30,7 @@ import {
SCSaveableThing,
SCFeedbackRequest,
SCFeedbackResponse,
SCUuid,
} from '@openstapps/core';
import {environment} from '../../../environments/environment';
import {StorageProvider} from '../storage/storage.provider';
@@ -41,6 +42,11 @@ export enum DataScope {
Remote = 'remote',
}
interface CacheItem<T> {
data: Promise<T>;
timestamp: number;
}
/**
* Generated class for the DataProvider provider.
*
@@ -70,6 +76,10 @@ export class DataProvider {
*/
private _storagePrefix = 'stapps.data';
readonly cache: Record<SCUuid, CacheItem<SCThings> | undefined> = {};
private maxCacheAge = 3600;
/**
* Version of the app (used for the header in communication with the backend)
*/
@@ -229,7 +239,17 @@ export class DataProvider {
return this.storageProvider.get<SCSaveableThing>(this.getDataKey(uid));
}
if (scope === DataScope.Remote) {
return this.client.getThing(uid);
const timestamp = Date.now();
const cacheItem = this.cache[uid];
if (cacheItem && timestamp - cacheItem.timestamp < this.maxCacheAge) {
return cacheItem.data;
}
const item = this.client.getThing(uid);
this.cache[uid] = {
data: item,
timestamp: timestamp,
};
return item;
}
const map: Map<DataScope, SCThings | SCSaveableThing> = new Map();
map.set(DataScope.Local, await this.get(uid, DataScope.Local));