Files
Momento/memento-note/lib/connections-cache.ts
Sepehr Ramezani e4d4e23dc7 chore: clean up repo for public release
- Remove BMAD framework, IDE configs, dev screenshots, test files,
  internal docs, and backup files
- Rename keep-notes/ to memento-note/
- Update all references from keep-notes to memento-note
- Add Apache 2.0 license with Commons Clause (non-commercial restriction)
- Add clean .gitignore and .env.docker.example
2026-04-20 22:48:06 +02:00

38 lines
896 B
TypeScript

// Cache with TTL for 15 minutes
const CACHE_TTL = 15 * 60 * 1000 // 15 minutes
interface CacheEntry {
count: number
timestamp: number
}
const cache = new Map<string, CacheEntry>()
export async function getConnectionsCount(noteId: string): Promise<number> {
const now = Date.now()
const cached = cache.get(noteId)
if (cached && (now - cached.timestamp) < CACHE_TTL) {
return cached.count
}
try {
const res = await fetch(`/api/ai/echo/connections?noteId=${noteId}&limit=1`)
if (!res.ok) {
throw new Error('Failed to fetch connections')
}
const data = await res.json()
const count = data.pagination?.total || 0
// Update cache for future calls
if (count > 0) {
cache.set(noteId, { count, timestamp: Date.now() })
}
return count
} catch (error) {
console.error('[ConnectionsCache] Failed to fetch connections:', error)
return 0
}
}