experiments in a post-browser web
10
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix: restore inline frecency function in Electron backend

The cross-boundary import from app/lib/frecency.js doesn't work at
runtime because the TS compiler outputs to dist/backend/ which doesn't
include app/lib/. Restore the inline function with a comment pointing
to the shared copy.

+15 -3
+15 -3
backend/electron/datastore.ts
··· 32 32 import { DEBUG } from './config.js'; 33 33 import { DATASTORE_VERSION } from '../version.js'; 34 34 import { addDeviceMetadata } from './device.js'; 35 - import { calculateItemFrecency } from '../../app/lib/frecency.js'; 36 35 37 36 // Load canonical schema for validation 38 37 // Path is relative to compiled JS in dist/backend/electron/ ··· 1035 1034 } 1036 1035 } 1037 1036 1038 - // calculateItemFrecency is imported from app/lib/frecency.js (shared frontend/backend module) 1039 - export { calculateItemFrecency }; 1037 + /** 1038 + * Calculate frecency score for an item based on visit history. 1039 + * Uses a time-decay algorithm where recent visits contribute more. 1040 + * NOTE: Shared copy lives in app/lib/frecency.js for frontend/Tauri use. 1041 + */ 1042 + export function calculateItemFrecency(visits: Array<{ timestamp: number; interacted: number; source: string }>): number { 1043 + let score = 0; 1044 + for (const visit of visits) { 1045 + const ageDays = (Date.now() - visit.timestamp) / (1000 * 60 * 60 * 24); 1046 + const decay = 1 / (1 + Math.pow(ageDays / 7, 0.5)); 1047 + const weight = visit.interacted ? 2 : (visit.source === 'direct' ? 0.5 : 1); 1048 + score += weight * decay; 1049 + } 1050 + return Math.round(score * 10); 1051 + } 1040 1052 1041 1053 /** 1042 1054 * Migrate ALL addresses to items (not just tagged ones).