Remove contact caching and add contact method standardization to migration template

• Remove contact caching: $contacts() always returns fresh data
• Simplify cache infrastructure: Remove unused contact TTL constants
• Add Phase 2.5 to migration template: Contact Method Standardization
• Update migration pattern: 4-phase → 5-phase Enhanced Migration Pattern
• Eliminate inconsistency: 12 components need $getAllContacts() → $contacts()

Migration Impact:
- Before: 70% non-cached, 30% cached contact fetching (inconsistent)
- After: 100% fresh contact data with unified $contacts() method
- Template enforces: Consistent contact patterns in all future migrations
This commit is contained in:
Matthew Raymer
2025-07-08 03:01:15 +00:00
parent 17efa7327d
commit a81e912b9c
2 changed files with 55 additions and 48 deletions

View File

@@ -91,9 +91,6 @@ const componentCaches = new WeakMap<
* 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
} as const;
@@ -555,25 +552,14 @@ export const PlatformServiceMixin = {
// =================================================
/**
* Load all contacts with caching - $contacts()
* Contacts are cached for 60 seconds for performance
* Load all contacts (always fresh) - $contacts()
* Always fetches fresh data from database for consistency
* @returns Promise<Contact[]> Array of contact objects
*/
async $contacts(): Promise<Contact[]> {
const cacheKey = "contacts_all";
const cached = this._getCached<Contact[]>(cacheKey);
if (cached) {
return cached;
}
const contacts = await this.$query(
return (await this.$query(
"SELECT * FROM contacts ORDER BY name",
);
return this._setCached(
cacheKey,
contacts as Contact[],
CACHE_DEFAULTS.contacts,
);
)) as Contact[];
},
/**
@@ -767,11 +753,10 @@ export const PlatformServiceMixin = {
},
/**
* Manually refresh contacts cache - $refreshContacts()
* Forces reload of contacts from database
* Get fresh contacts from database - $refreshContacts()
* Always returns fresh data (no caching)
*/
async $refreshContacts(): Promise<Contact[]> {
this._invalidateCache("contacts_all");
return await this.$contacts();
},
@@ -845,8 +830,6 @@ export const PlatformServiceMixin = {
safeContact.profileImageUrl,
],
);
// Invalidate contacts cache
this._invalidateCache("contacts_all");
return true;
} catch (error) {
logger.error("[PlatformServiceMixin] Error inserting contact:", error);
@@ -884,8 +867,6 @@ export const PlatformServiceMixin = {
params,
);
// Invalidate contacts cache
this._invalidateCache("contacts_all");
return true;
} catch (error) {
logger.error("[PlatformServiceMixin] Error updating contact:", error);
@@ -946,8 +927,6 @@ export const PlatformServiceMixin = {
async $deleteContact(did: string): Promise<boolean> {
try {
await this.$dbExec("DELETE FROM contacts WHERE did = ?", [did]);
// Invalidate contacts cache
this._invalidateCache("contacts_all");
return true;
} catch (error) {
logger.error("[PlatformServiceMixin] Error deleting contact:", error);