1
0
mirror of https://github.com/bpatrik/pigallery2.git synced 2024-12-25 02:04:15 +02:00

improving date structure update handling

This commit is contained in:
Patrik J. Braun 2018-11-18 22:56:05 +01:00
parent 7a322e2afa
commit 16c3a755ee
3 changed files with 15 additions and 3 deletions

View File

@ -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();

View File

@ -0,0 +1 @@
export const DataStructureVersion = 2;

View File

@ -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<T> {
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<AutoCompleteItem> {