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
This commit is contained in:
37
memento-note/lib/connections-cache.ts
Normal file
37
memento-note/lib/connections-cache.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
// 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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user