From 16c3a755ee633efa1d8e9b7be0533c588b94b38b Mon Sep 17 00:00:00 2001 From: "Patrik J. Braun" Date: Sun, 18 Nov 2018 22:56:05 +0100 Subject: [PATCH] improving date structure update handling --- backend/model/sql/SQLConnection.ts | 6 +++--- common/DataStructureVersion.ts | 1 + frontend/app/gallery/cache.gallery.service.ts | 11 +++++++++++ 3 files changed, 15 insertions(+), 3 deletions(-) create mode 100644 common/DataStructureVersion.ts diff --git a/backend/model/sql/SQLConnection.ts b/backend/model/sql/SQLConnection.ts index ee660a1f..ceeae65d 100644 --- a/backend/model/sql/SQLConnection.ts +++ b/backend/model/sql/SQLConnection.ts @@ -13,11 +13,11 @@ import {VersionEntity} from './enitites/VersionEntity'; import {Logger} from '../../Logger'; import {MediaEntity} from './enitites/MediaEntity'; import {VideoEntity} from './enitites/VideoEntity'; +import {DataStructureVersion} from '../../../common/DataStructureVersion'; export class SQLConnection { - private static VERSION = 2; constructor() { } @@ -92,14 +92,14 @@ export class SQLConnection { version = await connection.getRepository(VersionEntity).findOne(); } catch (ex) { } - if (version && version.version === SQLConnection.VERSION) { + if (version && version.version === DataStructureVersion) { return; } Logger.info('Updating database scheme'); if (!version) { version = new VersionEntity(); } - version.version = SQLConnection.VERSION; + version.version = DataStructureVersion; await connection.dropDatabase(); diff --git a/common/DataStructureVersion.ts b/common/DataStructureVersion.ts new file mode 100644 index 00000000..d951029d --- /dev/null +++ b/common/DataStructureVersion.ts @@ -0,0 +1 @@ +export const DataStructureVersion = 2; diff --git a/frontend/app/gallery/cache.gallery.service.ts b/frontend/app/gallery/cache.gallery.service.ts index 9fd5715d..75b28bb5 100644 --- a/frontend/app/gallery/cache.gallery.service.ts +++ b/frontend/app/gallery/cache.gallery.service.ts @@ -6,6 +6,7 @@ import {Config} from '../../../common/config/public/Config'; import {AutoCompleteItem, SearchTypes} from '../../../common/entities/AutoCompleteItem'; import {SearchResultDTO} from '../../../common/entities/SearchResultDTO'; import {MediaDTO} from '../../../common/entities/MediaDTO'; +import {DataStructureVersion} from '../../../common/DataStructureVersion'; interface CacheItem { timestamp: number; @@ -20,6 +21,16 @@ export class GalleryCacheService { private static INSTANT_SEARCH_PREFIX = 'instant_search:'; private static SEARCH_PREFIX = 'search:'; private static SEARCH_TYPE_PREFIX = ':type:'; + private static VERSION = 'version'; + + constructor() { + const version = parseInt(localStorage.getItem(GalleryCacheService.VERSION), 10) || 0; + if (version !== DataStructureVersion) { + localStorage.clear(); + localStorage.setItem(GalleryCacheService.VERSION, DataStructureVersion.toString()); + } + + } public getAutoComplete(text: string): Array {