MOBILE-3981 core: Optimize site tables
parent
4504d1ba8a
commit
b95c67874f
|
@ -108,6 +108,7 @@ export class CoreSite {
|
||||||
protected logger: CoreLogger;
|
protected logger: CoreLogger;
|
||||||
protected db?: SQLiteDB;
|
protected db?: SQLiteDB;
|
||||||
protected cacheTable: AsyncInstance<CoreDatabaseTable<CoreSiteWSCacheRecord>>;
|
protected cacheTable: AsyncInstance<CoreDatabaseTable<CoreSiteWSCacheRecord>>;
|
||||||
|
protected configTable: AsyncInstance<CoreDatabaseTable<CoreSiteConfigDBRecord, 'name'>>;
|
||||||
protected cleanUnicode = false;
|
protected cleanUnicode = false;
|
||||||
protected lastAutoLogin = 0;
|
protected lastAutoLogin = 0;
|
||||||
protected offlineDisabled = false;
|
protected offlineDisabled = false;
|
||||||
|
@ -146,6 +147,12 @@ export class CoreSite {
|
||||||
database: this.getDb(),
|
database: this.getDb(),
|
||||||
config: { cachingStrategy: CoreDatabaseCachingStrategy.None },
|
config: { cachingStrategy: CoreDatabaseCachingStrategy.None },
|
||||||
}));
|
}));
|
||||||
|
this.configTable = asyncInstance(() => CoreSites.getSiteTable(CoreSite.CONFIG_TABLE, {
|
||||||
|
siteId: this.getId(),
|
||||||
|
database: this.getDb(),
|
||||||
|
config: { cachingStrategy: CoreDatabaseCachingStrategy.Eager },
|
||||||
|
primaryKeyColumns: ['name'],
|
||||||
|
}));
|
||||||
this.setInfo(infos);
|
this.setInfo(infos);
|
||||||
this.calculateOfflineDisabled();
|
this.calculateOfflineDisabled();
|
||||||
|
|
||||||
|
@ -1825,7 +1832,7 @@ export class CoreSite {
|
||||||
* @return Promise resolved when done.
|
* @return Promise resolved when done.
|
||||||
*/
|
*/
|
||||||
async deleteSiteConfig(name: string): Promise<void> {
|
async deleteSiteConfig(name: string): Promise<void> {
|
||||||
await this.getDb().deleteRecords(CoreSite.CONFIG_TABLE, { name });
|
await this.configTable.deleteByPrimaryKey({ name });
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1837,7 +1844,7 @@ export class CoreSite {
|
||||||
*/
|
*/
|
||||||
async getLocalSiteConfig<T extends number | string>(name: string, defaultValue?: T): Promise<T> {
|
async getLocalSiteConfig<T extends number | string>(name: string, defaultValue?: T): Promise<T> {
|
||||||
try {
|
try {
|
||||||
const entry = await this.getDb().getRecord<CoreSiteConfigDBRecord>(CoreSite.CONFIG_TABLE, { name });
|
const entry = await this.configTable.getOneByPrimaryKey({ name });
|
||||||
|
|
||||||
return <T> entry.value;
|
return <T> entry.value;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
@ -1857,7 +1864,7 @@ export class CoreSite {
|
||||||
* @return Promise resolved when done.
|
* @return Promise resolved when done.
|
||||||
*/
|
*/
|
||||||
async setLocalSiteConfig(name: string, value: number | string): Promise<void> {
|
async setLocalSiteConfig(name: string, value: number | string): Promise<void> {
|
||||||
await this.getDb().insertRecord(CoreSite.CONFIG_TABLE, { name, value });
|
await this.configTable.insert({ name, value });
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue