diff --git a/backend/database/core.ts b/backend/database/core.ts index ae52b816..a68699f8 100644 --- a/backend/database/core.ts +++ b/backend/database/core.ts @@ -2,7 +2,7 @@ import { CannotCommitError, getDbError, NotFoundError, - ValueError + ValueError, } from 'fyo/utils/errors'; import { knex, Knex } from 'knex'; import { @@ -11,12 +11,12 @@ import { RawValue, Schema, SchemaMap, - TargetField + TargetField, } from '../../schemas/types'; import { getIsNullOrUndef, getRandomString, - getValueMapFromList + getValueMapFromList, } from '../../utils'; import { DatabaseBase, GetAllOptions, QueryFilter } from '../../utils/db/types'; import { getDefaultMetaFieldValueMap, sqliteTypeMap, SYSTEM } from '../helpers'; @@ -24,7 +24,7 @@ import { ColumnDiff, FieldValueMap, GetQueryBuilderOptions, - SingleValue + SingleValue, } from './types'; /** diff --git a/dummy/index.ts b/dummy/index.ts index 2f3923ad..987f2bd8 100644 --- a/dummy/index.ts +++ b/dummy/index.ts @@ -29,7 +29,7 @@ export async function setupDummyInstance( baseCount: number = 1000, notifier?: Notifier ) { - fyo.purgeCache(); + await fyo.purgeCache(); notifier?.(fyo.t`Setting Up Instance`, -1); const options = { logo: null, diff --git a/fyo/core/authHandler.ts b/fyo/core/authHandler.ts index f104198b..13e1c203 100644 --- a/fyo/core/authHandler.ts +++ b/fyo/core/authHandler.ts @@ -107,7 +107,7 @@ export class AuthHandler { // TODO: Implement this with auth flow } - purgeCache() {} + async purgeCache() {} #getServerURL() { return this.#config.serverURL || ''; diff --git a/fyo/core/dbHandler.ts b/fyo/core/dbHandler.ts index 3eab4495..70ad8c22 100644 --- a/fyo/core/dbHandler.ts +++ b/fyo/core/dbHandler.ts @@ -85,7 +85,8 @@ export class DatabaseHandler extends DatabaseBase { } } - purgeCache() { + async purgeCache() { + await this.close(); this.dbPath = undefined; this.#schemaMap = {}; this.fieldValueMap = {}; @@ -214,7 +215,6 @@ export class DatabaseHandler extends DatabaseBase { async close(): Promise { await this.#demux.call('close'); - this.purgeCache(); } /** diff --git a/fyo/core/docHandler.ts b/fyo/core/docHandler.ts index f40343a2..e67ef174 100644 --- a/fyo/core/docHandler.ts +++ b/fyo/core/docHandler.ts @@ -26,7 +26,7 @@ export class DocHandler { this.observer = new Observable(); } - purgeCache() { + async purgeCache() { this.init(); } diff --git a/fyo/index.ts b/fyo/index.ts index 5d52e0bc..166fcc15 100644 --- a/fyo/index.ts +++ b/fyo/index.ts @@ -202,7 +202,7 @@ export class Fyo { return value; } - purgeCache() { + async purgeCache() { this.pesa = getMoneyMaker({ currency: DEFAULT_CURRENCY, precision: DEFAULT_INTERNAL_PRECISION, @@ -216,9 +216,9 @@ export class Fyo { this.currencySymbols = {}; this.errorLog = []; this.temp = {}; - this.db.purgeCache(); - this.auth.purgeCache(); - this.doc.purgeCache(); + await this.db.purgeCache(); + await this.auth.purgeCache(); + await this.doc.purgeCache(); } store = { diff --git a/fyo/tests/testFyo.spec.ts b/fyo/tests/testFyo.spec.ts index 16134be2..c1078f8e 100644 --- a/fyo/tests/testFyo.spec.ts +++ b/fyo/tests/testFyo.spec.ts @@ -34,7 +34,7 @@ describe('Fyo Init', function () { true, 'non zero schemas' ); - await fyo.db.close(); + await fyo.db.purgeCache(); }); }); diff --git a/src/App.vue b/src/App.vue index df1b8551..4788737d 100644 --- a/src/App.vue +++ b/src/App.vue @@ -149,7 +149,7 @@ export default { async showDbSelector() { fyo.config.set('lastSelectedFilePath', null); fyo.telemetry.stop(); - fyo.purgeCache(); + await fyo.purgeCache(); this.activeScreen = 'DatabaseSelector'; this.dbPath = ''; this.searcher = null; diff --git a/src/initFyo.ts b/src/initFyo.ts index c3b83db9..3bdc72e2 100644 --- a/src/initFyo.ts +++ b/src/initFyo.ts @@ -11,7 +11,7 @@ async function closeDbIfConnected() { return; } - await fyo.db.close(); + await fyo.db.purgeCache(); } export async function initializeInstance( diff --git a/src/pages/DatabaseSelector.vue b/src/pages/DatabaseSelector.vue index fa5102b5..732ac3ad 100644 --- a/src/pages/DatabaseSelector.vue +++ b/src/pages/DatabaseSelector.vue @@ -299,7 +299,7 @@ export default { ); updateConfigFiles(fyo); - fyo.purgeCache(); + await fyo.purgeCache(); await this.setFiles(); this.creatingDemo = false;