Browse Source

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
web-serve-fix
Matthew Raymer 3 weeks ago
parent
commit
a81e912b9c
  1. 70
      docs/migration-templates/COMPLETE_MIGRATION_CHECKLIST.md
  2. 33
      src/utils/PlatformServiceMixin.ts

70
docs/migration-templates/COMPLETE_MIGRATION_CHECKLIST.md

@ -3,6 +3,19 @@
## Overview ## Overview
This checklist ensures NO migration steps are forgotten. **Every component migration MUST complete ALL sections.** This checklist ensures NO migration steps are forgotten. **Every component migration MUST complete ALL sections.**
## Requirements
**EVERY component migration MUST complete ALL FIVE migration types:**
1. **Database Migration**: Replace databaseUtil calls with PlatformServiceMixin methods
2. **SQL Abstraction**: Replace raw SQL queries with service methods
2.5. **Contact Method Standardization**: Replace inconsistent contact fetching patterns
3. **Notification Migration**: Replace `$notify()` calls with helper methods + centralized constants
4. **Template Streamlining**: Extract repeated expressions and complex logic to computed properties
**❌ INCOMPLETE**: Any migration missing one of these steps
**✅ COMPLETE**: All five patterns implemented with code quality review
## ⏱️ **TIME TRACKING REQUIREMENT**: All migrations must be timed and performance recorded ## ⏱️ **TIME TRACKING REQUIREMENT**: All migrations must be timed and performance recorded
## 🎯 **USER CONTROL COMMANDS**: For seamless migration workflow ## 🎯 **USER CONTROL COMMANDS**: For seamless migration workflow
@ -126,20 +139,35 @@ git commit -m "[user-approved-message]"
- [ ] Generic queries → appropriate service methods - [ ] Generic queries → appropriate service methods
- [ ] **NO RAW SQL ALLOWED**: All database operations through service layer - [ ] **NO RAW SQL ALLOWED**: All database operations through service layer
## Phase 2.5: Contact Method Standardization
### [ ] 8. Standardize Contact Fetching Methods
- [ ] **CRITICAL**: Replace `this.$getAllContacts()``this.$contacts()`
- [ ] **REASON**: Eliminate inconsistent contact fetching patterns
- [ ] **BENEFIT**: All components use same contact data source
- [ ] **VALIDATION**: Search for `$getAllContacts` and replace with `$contacts`
- [ ] **CONSISTENCY**: All contact operations use unified approach
### [ ] 9. Verify Contact Method Consistency
- [ ] **NO** `$getAllContacts()` calls remain in component
- [ ] **ALL** contact fetching uses `$contacts()` method
- [ ] **CONSISTENT** contact data across component lifecycle
- [ ] **VALIDATED**: Component uses standardized contact API
## Phase 3: Notification Migration ## Phase 3: Notification Migration
### [ ] 8. Add Notification Infrastructure ### [ ] 10. Add Notification Infrastructure
- [ ] Add import: `import { createNotifyHelpers, TIMEOUTS } from "@/utils/notify"` - [ ] Add import: `import { createNotifyHelpers, TIMEOUTS } from "@/utils/notify"`
- [ ] Add property: `notify!: ReturnType<typeof createNotifyHelpers>;` - [ ] Add property: `notify!: ReturnType<typeof createNotifyHelpers>;`
- [ ] Add initialization: `created() { this.notify = createNotifyHelpers(this.$notify); }` - [ ] Add initialization: `created() { this.notify = createNotifyHelpers(this.$notify); }`
### [ ] 9. Add Notification Constants to Central File ### [ ] 11. Add Notification Constants to Central File
- [ ] **CRITICAL**: Add constants to `src/constants/notifications.ts` (NOT local constants) - [ ] **CRITICAL**: Add constants to `src/constants/notifications.ts` (NOT local constants)
- [ ] Use naming pattern: `NOTIFY_[COMPONENT]_[ACTION]` (e.g., `NOTIFY_OFFER_SETTINGS_ERROR`) - [ ] Use naming pattern: `NOTIFY_[COMPONENT]_[ACTION]` (e.g., `NOTIFY_OFFER_SETTINGS_ERROR`)
- [ ] Import constants: `import { NOTIFY_X, NOTIFY_Y } from "@/constants/notifications"` - [ ] Import constants: `import { NOTIFY_X, NOTIFY_Y } from "@/constants/notifications"`
- [ ] **NO LOCAL CONSTANTS**: All notification text must be centralized - [ ] **NO LOCAL CONSTANTS**: All notification text must be centralized
### [ ] 10. Replace Notification Calls ### [ ] 12. Replace Notification Calls
- [ ] **Warning**: `this.$notify({type: "warning"})``this.notify.warning(CONSTANT.message, TIMEOUTS.LONG)` - [ ] **Warning**: `this.$notify({type: "warning"})``this.notify.warning(CONSTANT.message, TIMEOUTS.LONG)`
- [ ] **Error**: `this.$notify({type: "danger"})``this.notify.error(CONSTANT.message, TIMEOUTS.LONG)` - [ ] **Error**: `this.$notify({type: "danger"})``this.notify.error(CONSTANT.message, TIMEOUTS.LONG)`
- [ ] **Success**: `this.$notify({type: "success"})``this.notify.success(CONSTANT.message, TIMEOUTS.STANDARD)` - [ ] **Success**: `this.$notify({type: "success"})``this.notify.success(CONSTANT.message, TIMEOUTS.STANDARD)`
@ -147,7 +175,7 @@ git commit -m "[user-approved-message]"
- [ ] **Confirm**: `this.$notify({type: "confirm"})``this.notify.confirm(message, onYes)` - [ ] **Confirm**: `this.$notify({type: "confirm"})``this.notify.confirm(message, onYes)`
- [ ] **Standard patterns**: Use `this.notify.confirmationSubmitted()`, `this.notify.sent()`, etc. - [ ] **Standard patterns**: Use `this.notify.confirmationSubmitted()`, `this.notify.sent()`, etc.
### [ ] 11. Constants vs Literal Strings ### [ ] 13. Constants vs Literal Strings
- [ ] **Use constants** for static, reusable messages - [ ] **Use constants** for static, reusable messages
- [ ] **Use literal strings** for dynamic messages with variables - [ ] **Use literal strings** for dynamic messages with variables
- [ ] **Extract literals from complex modals** - Even raw `$notify` calls should use constants for text - [ ] **Extract literals from complex modals** - Even raw `$notify` calls should use constants for text
@ -155,19 +183,19 @@ git commit -m "[user-approved-message]"
## Phase 4: Template Streamlining ## Phase 4: Template Streamlining
### [ ] 12. Identify Template Complexity Patterns ### [ ] 14. Identify Template Complexity Patterns
- [ ] **Repeated CSS Classes**: Long Tailwind strings used multiple times - [ ] **Repeated CSS Classes**: Long Tailwind strings used multiple times
- [ ] **Complex Configuration Objects**: Multi-line objects in template - [ ] **Complex Configuration Objects**: Multi-line objects in template
- [ ] **Repeated Function Calls**: Same logic executed multiple times - [ ] **Repeated Function Calls**: Same logic executed multiple times
- [ ] **Complex Conditional Logic**: Nested ternary or complex boolean expressions - [ ] **Complex Conditional Logic**: Nested ternary or complex boolean expressions
### [ ] 13. Extract to Computed Properties ### [ ] 15. Extract to Computed Properties
- [ ] **CSS Class Groups**: Extract repeated styling to computed properties - [ ] **CSS Class Groups**: Extract repeated styling to computed properties
- [ ] **Configuration Objects**: Move router configs, form configs to computed - [ ] **Configuration Objects**: Move router configs, form configs to computed
- [ ] **Conditional Logic**: Extract complex `v-if` conditions to computed properties - [ ] **Conditional Logic**: Extract complex `v-if` conditions to computed properties
- [ ] **Dynamic Values**: Convert repeated calculations to cached computed properties - [ ] **Dynamic Values**: Convert repeated calculations to cached computed properties
### [ ] 14. Document Computed Properties ### [ ] 16. Document Computed Properties
- [ ] **JSDoc Comments**: Add comprehensive comments for all computed properties - [ ] **JSDoc Comments**: Add comprehensive comments for all computed properties
- [ ] **Purpose Documentation**: Explain what template complexity each property solves - [ ] **Purpose Documentation**: Explain what template complexity each property solves
- [ ] **Organized Sections**: Group related computed properties with section headers - [ ] **Organized Sections**: Group related computed properties with section headers
@ -175,19 +203,19 @@ git commit -m "[user-approved-message]"
## Phase 5: Code Quality Review ## Phase 5: Code Quality Review
### [ ] 15. Template Quality Assessment ### [ ] 17. Template Quality Assessment
- [ ] **Readability**: Template is easy to scan and understand - [ ] **Readability**: Template is easy to scan and understand
- [ ] **Maintainability**: Styling changes can be made in one place - [ ] **Maintainability**: Styling changes can be made in one place
- [ ] **Performance**: Computed properties cache expensive operations - [ ] **Performance**: Computed properties cache expensive operations
- [ ] **Consistency**: Similar patterns use similar solutions - [ ] **Consistency**: Similar patterns use similar solutions
### [ ] 16. Component Architecture Review ### [ ] 18. Component Architecture Review
- [ ] **Single Responsibility**: Component has clear, focused purpose - [ ] **Single Responsibility**: Component has clear, focused purpose
- [ ] **Props Interface**: Clear, well-documented component props - [ ] **Props Interface**: Clear, well-documented component props
- [ ] **Event Emissions**: Appropriate event handling and emission - [ ] **Event Emissions**: Appropriate event handling and emission
- [ ] **State Management**: Component state is minimal and well-organized - [ ] **State Management**: Component state is minimal and well-organized
### [ ] 17. Code Organization Review ### [ ] 19. Code Organization Review
- [ ] **Import Organization**: Imports are grouped logically (Vue, constants, services) - [ ] **Import Organization**: Imports are grouped logically (Vue, constants, services)
- [ ] **Method Organization**: Methods are grouped by purpose with section headers - [ ] **Method Organization**: Methods are grouped by purpose with section headers
- [ ] **Property Organization**: Data properties are documented and organized - [ ] **Property Organization**: Data properties are documented and organized
@ -195,17 +223,17 @@ git commit -m "[user-approved-message]"
## Validation Phase ## Validation Phase
### [ ] 18. Run Validation Script ### [ ] 20. Run Validation Script
- [ ] Execute: `scripts/validate-migration.sh` - [ ] Execute: `scripts/validate-migration.sh`
- [ ] **MUST show**: "Technically Compliant" (not "Mixed Pattern") - [ ] **MUST show**: "Technically Compliant" (not "Mixed Pattern")
- [ ] **Zero** legacy patterns detected - [ ] **Zero** legacy patterns detected
### [ ] 19. Run Linting ### [ ] 21. Run Linting
- [ ] Execute: `npm run lint-fix` - [ ] Execute: `npm run lint-fix`
- [ ] **Zero errors** introduced - [ ] **Zero errors** introduced
- [ ] **TypeScript compiles** without errors - [ ] **TypeScript compiles** without errors
### [ ] 20. Manual Code Review ### [ ] 22. Manual Code Review
- [ ] **NO** `databaseUtil` imports or calls - [ ] **NO** `databaseUtil` imports or calls
- [ ] **NO** raw SQL queries (`SELECT`, `INSERT`, `UPDATE`, `DELETE`) - [ ] **NO** raw SQL queries (`SELECT`, `INSERT`, `UPDATE`, `DELETE`)
- [ ] **NO** `$notify()` calls with object syntax - [ ] **NO** `$notify()` calls with object syntax
@ -217,25 +245,25 @@ git commit -m "[user-approved-message]"
## ⏱️ Time Tracking & Commit Phase ## ⏱️ Time Tracking & Commit Phase
### [ ] 21. End Time Tracking ### [ ] 23. End Time Tracking
- [ ] **MANDATORY**: Run `./scripts/time-migration.sh [ComponentName.vue] end` - [ ] **MANDATORY**: Run `./scripts/time-migration.sh [ComponentName.vue] end`
- [ ] Record total duration from terminal output - [ ] Record total duration from terminal output
- [ ] Note any blockers or issues that impacted timing - [ ] Note any blockers or issues that impacted timing
### [ ] 22. Commit with Time Data ### [ ] 24. Commit with Time Data
- [ ] **MANDATORY**: Include time data in commit message - [ ] **MANDATORY**: Include time data in commit message
- [ ] Use template: `Complete [ComponentName] Enhanced Triple Migration Pattern (X minutes)` - [ ] Use template: `Complete [ComponentName] Enhanced Triple Migration Pattern (X minutes)`
- [ ] Include complexity level and any issues encountered - [ ] Include complexity level and any issues encountered
- [ ] Document specific changes made in each phase - [ ] Document specific changes made in each phase
### [ ] 23. Performance Analysis ### [ ] 25. Performance Analysis
- [ ] Compare actual time vs. estimated time for complexity level - [ ] Compare actual time vs. estimated time for complexity level
- [ ] Note if component was faster/slower than expected - [ ] Note if component was faster/slower than expected
- [ ] Document any efficiency improvements discovered - [ ] Document any efficiency improvements discovered
## Documentation Phase ## Documentation Phase
### [ ] 24. Update Migration Documentation ### [ ] 26. Update Migration Documentation
- [ ] Create `docs/migration-testing/[COMPONENT]_MIGRATION.md` - [ ] Create `docs/migration-testing/[COMPONENT]_MIGRATION.md`
- [ ] Document all changes made (database, SQL, notifications, template) - [ ] Document all changes made (database, SQL, notifications, template)
- [ ] Include before/after examples for template streamlining - [ ] Include before/after examples for template streamlining
@ -243,7 +271,7 @@ git commit -m "[user-approved-message]"
- [ ] Provide a guide to finding the components in the user interface - [ ] Provide a guide to finding the components in the user interface
- [ ] Include code quality review notes - [ ] Include code quality review notes
### [ ] 25. Update Testing Tracker ### [ ] 27. Update Testing Tracker
- [ ] Update `docs/migration-testing/HUMAN_TESTING_TRACKER.md` - [ ] Update `docs/migration-testing/HUMAN_TESTING_TRACKER.md`
- [ ] Mark component as "Ready for Testing" - [ ] Mark component as "Ready for Testing"
- [ ] Include notes about migration completed with template streamlining - [ ] Include notes about migration completed with template streamlining
@ -251,7 +279,7 @@ git commit -m "[user-approved-message]"
## Human Testing Phase ## Human Testing Phase
### [ ] 26. Test All Functionality ### [ ] 28. Test All Functionality
- [ ] **Core functionality** works correctly - [ ] **Core functionality** works correctly
- [ ] **Database operations** function properly - [ ] **Database operations** function properly
- [ ] **Notifications** display correctly with proper timing - [ ] **Notifications** display correctly with proper timing
@ -259,14 +287,14 @@ git commit -m "[user-approved-message]"
- [ ] **Template rendering** performs smoothly with computed properties - [ ] **Template rendering** performs smoothly with computed properties
- [ ] **Cross-platform** compatibility (web/mobile) - [ ] **Cross-platform** compatibility (web/mobile)
### [ ] 27. Confirm Testing Complete ### [ ] 29. Confirm Testing Complete
- [ ] User confirms component works correctly - [ ] User confirms component works correctly
- [ ] Update testing tracker with results - [ ] Update testing tracker with results
- [ ] Mark as "Human Tested" in validation script - [ ] Mark as "Human Tested" in validation script
## Final Validation ## Final Validation
### [ ] 28. Comprehensive Check ### [ ] 30. Comprehensive Check
- [ ] Component shows as "Technically Compliant" in validation - [ ] Component shows as "Technically Compliant" in validation
- [ ] All manual testing passed - [ ] All manual testing passed
- [ ] Zero legacy patterns remain - [ ] Zero legacy patterns remain

33
src/utils/PlatformServiceMixin.ts

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

Loading…
Cancel
Save