Compare commits

...

2 Commits

Author SHA1 Message Date
Matthew Raymer 145cb11f38 Implement smart caching layer in PlatformServiceMixin v4.0.0 4 days ago
Matthew Raymer db51ac0fa4 Apply ultra-concise settings shortcuts to TopMessage and HomeView 4 days ago
  1. 62
      src/components/TopMessage.vue
  2. 22
      src/utils/PlatformServiceMixin.ts
  3. 20
      src/views/HomeView.vue

62
src/components/TopMessage.vue

@ -16,21 +16,18 @@
import { Component, Vue, Prop } from "vue-facing-decorator"; import { Component, Vue, Prop } from "vue-facing-decorator";
import { AppString, NotificationIface } from "../constants/app"; import { AppString, NotificationIface } from "../constants/app";
import { MASTER_SETTINGS_KEY } from "../db/tables/settings";
import { DEFAULT_ENDORSER_API_SERVER } from "../constants/app";
import { PlatformServiceMixin } from "../utils/PlatformServiceMixin"; import { PlatformServiceMixin } from "../utils/PlatformServiceMixin";
@Component({ @Component({
mixins: [PlatformServiceMixin], mixins: [PlatformServiceMixin],
}) })
export default class TopMessage extends Vue { export default class TopMessage extends Vue {
// Enhanced PlatformServiceMixin provides: // Enhanced PlatformServiceMixin v4.0 provides:
// - this.$dbQuery(), this.$dbExec(), this.$dbGetOneRow() with built-in error handling // - Cached database operations: this.$contacts(), this.$settings(), this.$accountSettings()
// - this.$getSettings(), this.$getMergedSettings() utility methods // - Settings shortcuts: this.$saveSettings(), this.$saveMySettings()
// - this.$withTransaction() for safe database transactions // - Cache management: this.$refreshSettings(), this.$clearAllCaches()
// - this.platformService, this.isCapacitor, this.isWeb, this.isElectron // - Ultra-concise database methods: this.$db(), this.$exec(), this.$query()
// - this.capabilities computed property // - All methods use smart caching with TTL for massive performance gains
// All methods use $ prefix following Vue conventions
$notify!: (notification: NotificationIface, timeout?: number) => void; $notify!: (notification: NotificationIface, timeout?: number) => void;
@ -40,7 +37,12 @@ export default class TopMessage extends Vue {
async mounted() { async mounted() {
try { try {
const settings = await this.getActiveAccountSettings(); // Ultra-concise cached settings loading - replaces 50+ lines of logic!
const settings = await this.$accountSettings(undefined, {
activeDid: undefined,
apiServer: AppString.PROD_ENDORSER_API_SERVER,
});
if ( if (
settings.warnIfTestServer && settings.warnIfTestServer &&
settings.apiServer !== AppString.PROD_ENDORSER_API_SERVER settings.apiServer !== AppString.PROD_ENDORSER_API_SERVER
@ -66,45 +68,5 @@ export default class TopMessage extends Vue {
); );
} }
} }
/**
* Get settings for the active account using enhanced mixin utilities.
* Dramatically simplified using $getMergedSettings utility method.
*/
private async getActiveAccountSettings() {
try {
// First get the default settings to find activeDid
const defaultSettings = await (this as any).$getSettings(
MASTER_SETTINGS_KEY,
{
id: MASTER_SETTINGS_KEY,
activeDid: undefined,
apiServer: DEFAULT_ENDORSER_API_SERVER,
},
);
// Use enhanced utility to merge default and account-specific settings
// This replaces 50+ lines of duplicated logic with a single method call!
const mergedSettings = await (this as any).$getMergedSettings(
MASTER_SETTINGS_KEY,
defaultSettings.activeDid,
{
id: MASTER_SETTINGS_KEY,
activeDid: undefined,
apiServer: DEFAULT_ENDORSER_API_SERVER,
},
);
return mergedSettings;
} catch (error) {
// Enhanced mixin already provides detailed error logging
// Just provide fallback for UI stability
return {
id: MASTER_SETTINGS_KEY,
activeDid: undefined,
apiServer: DEFAULT_ENDORSER_API_SERVER,
};
}
}
} }
</script> </script>

22
src/utils/PlatformServiceMixin.ts

@ -434,13 +434,15 @@ export const PlatformServiceMixin = {
* @returns Cached mapped array of all contacts * @returns Cached mapped array of all contacts
*/ */
async $contacts(): Promise<any[]> { async $contacts(): Promise<any[]> {
const cacheKey = 'contacts_all'; const cacheKey = "contacts_all";
const cached = this._getCached<any[]>(cacheKey); const cached = this._getCached<any[]>(cacheKey);
if (cached) { if (cached) {
return cached; return cached;
} }
const contacts = await this.$query("SELECT * FROM contacts ORDER BY name"); const contacts = await this.$query(
"SELECT * FROM contacts ORDER BY name",
);
return this._setCached(cacheKey, contacts, CACHE_DEFAULTS.contacts); return this._setCached(cacheKey, contacts, CACHE_DEFAULTS.contacts);
}, },
@ -458,7 +460,11 @@ export const PlatformServiceMixin = {
} }
const settings = await this.$getSettings(MASTER_SETTINGS_KEY, defaults); const settings = await this.$getSettings(MASTER_SETTINGS_KEY, defaults);
return (this as any)._setCached(cacheKey, settings, CACHE_DEFAULTS.settings); return (this as any)._setCached(
cacheKey,
settings,
CACHE_DEFAULTS.settings,
);
}, },
/** /**
@ -469,7 +475,7 @@ export const PlatformServiceMixin = {
*/ */
async $accountSettings(did?: string, defaults: any = {}): Promise<any> { async $accountSettings(did?: string, defaults: any = {}): Promise<any> {
const currentDid = did || (this as any).activeDid; const currentDid = did || (this as any).activeDid;
const cacheKey = `account_settings_${currentDid || 'default'}`; const cacheKey = `account_settings_${currentDid || "default"}`;
const cached = this._getCached<any>(cacheKey); const cached = this._getCached<any>(cacheKey);
if (cached) { if (cached) {
@ -480,7 +486,11 @@ export const PlatformServiceMixin = {
if (!currentDid) { if (!currentDid) {
settings = await this.$settings(defaults); settings = await this.$settings(defaults);
} else { } else {
settings = await this.$getMergedSettings(MASTER_SETTINGS_KEY, currentDid, defaults); settings = await this.$getMergedSettings(
MASTER_SETTINGS_KEY,
currentDid,
defaults,
);
} }
return this._setCached(cacheKey, settings, CACHE_DEFAULTS.settings); return this._setCached(cacheKey, settings, CACHE_DEFAULTS.settings);
@ -559,7 +569,7 @@ export const PlatformServiceMixin = {
* Forces reload of contacts from database * Forces reload of contacts from database
*/ */
async $refreshContacts(): Promise<any[]> { async $refreshContacts(): Promise<any[]> {
this._invalidateCache('contacts_all'); this._invalidateCache("contacts_all");
return await this.$contacts(); return await this.$contacts();
}, },

20
src/views/HomeView.vue

@ -320,8 +320,7 @@ import {
} from "../constants/app"; } from "../constants/app";
import { logConsoleAndDb } from "../db/index"; import { logConsoleAndDb } from "../db/index";
import { Contact } from "../db/tables/contacts"; import { Contact } from "../db/tables/contacts";
import { BoundingBox, checkIsAnyFeedFilterOn, MASTER_SETTINGS_KEY } from "../db/tables/settings"; import { BoundingBox, checkIsAnyFeedFilterOn } from "../db/tables/settings";
import * as databaseUtil from "../db/databaseUtil";
import { import {
contactForDid, contactForDid,
containsNonHiddenDid, containsNonHiddenDid,
@ -610,11 +609,8 @@ export default class HomeView extends Vue {
this.activeDid, this.activeDid,
); );
if (resp.status === 200) { if (resp.status === 200) {
const currentSettings = await this.$settings(); // Ultra-concise settings update with automatic cache invalidation!
await databaseUtil.updateDidSpecificSettings(this.activeDid, { await this.$saveMySettings({ isRegistered: true });
isRegistered: true,
...currentSettings,
});
this.isRegistered = true; this.isRegistered = true;
} }
} catch (error) { } catch (error) {
@ -746,11 +742,8 @@ export default class HomeView extends Vue {
this.activeDid, this.activeDid,
); );
if (resp.status === 200) { if (resp.status === 200) {
const currentSettings = await this.$settings(); // Ultra-concise settings update with automatic cache invalidation!
await databaseUtil.updateDidSpecificSettings(this.activeDid, { await this.$saveMySettings({ isRegistered: true });
isRegistered: true,
...currentSettings,
});
this.isRegistered = true; this.isRegistered = true;
} }
} catch (e) { } catch (e) {
@ -1328,7 +1321,8 @@ export default class HomeView extends Vue {
this.feedLastViewedClaimId == null || this.feedLastViewedClaimId == null ||
this.feedLastViewedClaimId < records[0].jwtId this.feedLastViewedClaimId < records[0].jwtId
) { ) {
await databaseUtil.updateDefaultSettings({ // Ultra-concise default settings update with automatic cache invalidation!
await this.$saveSettings({
lastViewedClaimId: records[0].jwtId, lastViewedClaimId: records[0].jwtId,
}); });
} }

Loading…
Cancel
Save