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. 30
      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 { 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";
@Component({
mixins: [PlatformServiceMixin],
})
export default class TopMessage extends Vue {
// Enhanced PlatformServiceMixin provides:
// - this.$dbQuery(), this.$dbExec(), this.$dbGetOneRow() with built-in error handling
// - this.$getSettings(), this.$getMergedSettings() utility methods
// - this.$withTransaction() for safe database transactions
// - this.platformService, this.isCapacitor, this.isWeb, this.isElectron
// - this.capabilities computed property
// All methods use $ prefix following Vue conventions
// Enhanced PlatformServiceMixin v4.0 provides:
// - Cached database operations: this.$contacts(), this.$settings(), this.$accountSettings()
// - Settings shortcuts: this.$saveSettings(), this.$saveMySettings()
// - Cache management: this.$refreshSettings(), this.$clearAllCaches()
// - Ultra-concise database methods: this.$db(), this.$exec(), this.$query()
// - All methods use smart caching with TTL for massive performance gains
$notify!: (notification: NotificationIface, timeout?: number) => void;
@ -40,7 +37,12 @@ export default class TopMessage extends Vue {
async mounted() {
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 (
settings.warnIfTestServer &&
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>

30
src/utils/PlatformServiceMixin.ts

@ -63,10 +63,10 @@ const componentCaches = new WeakMap<any, Map<string, CacheEntry<any>>>();
* Cache configuration constants
*/
const CACHE_DEFAULTS = {
settings: 30000, // 30 seconds TTL for settings
contacts: 60000, // 60 seconds TTL for contacts
accounts: 30000, // 30 seconds TTL for accounts
default: 15000, // 15 seconds default TTL
settings: 30000, // 30 seconds TTL for settings
contacts: 60000, // 60 seconds TTL for contacts
accounts: 30000, // 30 seconds TTL for accounts
default: 15000, // 15 seconds default TTL
} as const;
/**
@ -434,13 +434,15 @@ export const PlatformServiceMixin = {
* @returns Cached mapped array of all contacts
*/
async $contacts(): Promise<any[]> {
const cacheKey = 'contacts_all';
const cacheKey = "contacts_all";
const cached = this._getCached<any[]>(cacheKey);
if (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);
},
@ -458,7 +460,11 @@ export const PlatformServiceMixin = {
}
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> {
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);
if (cached) {
@ -480,7 +486,11 @@ export const PlatformServiceMixin = {
if (!currentDid) {
settings = await this.$settings(defaults);
} 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);
@ -559,7 +569,7 @@ export const PlatformServiceMixin = {
* Forces reload of contacts from database
*/
async $refreshContacts(): Promise<any[]> {
this._invalidateCache('contacts_all');
this._invalidateCache("contacts_all");
return await this.$contacts();
},

20
src/views/HomeView.vue

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

Loading…
Cancel
Save