Commit graph naco-api/internal/server/cache.go
Author SHA1 Message Date
19ae0d781a
fix(server): bound post cache size with earliest-expiry eviction
Cap the post TTL cache at 10000 entries; once full, evict the entry with the
earliest expiry instead of growing without bound.
2026-09-13 22:24:42 +00:00
ee2829b818
refactor: pointer-ify profile/post slices across backends, converters, and tests 2026-09-08 01:08:28 +00:00
a218b8fbf5
refactor(server): split server.go into focused modules (phases 1-4)
Phase 1: mechanical splits
- platform.go: determinePlatform
- settlement.go: settleHook, buildRequirements, parseActiveNetworks
- posts_convert.go: bsky/ap/nostr/twitter single converters
- actors.go: searchActorsAll, dedupeActors, normalizeHandle
- posts.go: fetchSinglePost/fetchLatestPosts/fetchPostsInTime/fetchFeed
- style.go: getStyleProfile, requestStyleProfile*, enrichCrossPlatform,
  getSimilarProfiles, buildStyleProfile, fetchProfilePosts, toItems
- prewarm.go: StartPrewarm, discoverInterestingAuthors, prewarmOne, startPostPruner

Phase 2: deduplicate registerTools
- tools.go: table-driven payableDef + schemaExtra helper, analyticsInput reuse
- server.go 1814 -> 180 lines, registerTools 470 -> 150 lines

Phase 3: unify platform dispatch
- cache.go: generic cachedFetch[T]
- posts_convert.go: batch converters (blueskyFeedViewsToResponses,
  apPosts*ToResponses, nostr/twitter variants) and clustering Item
  variants (blueskyFeedViewsToAnalyticsItems etc.)
- posts.go: use cachedFetch + batch helpers, fetchFeed via helper
- style.go: fetchProfilePosts via *ToItems helpers
- analytics.go: fetchPostsInTimeForAnalytics/fetchTwitterFromAPI via analytics helpers

Phase 4: slim bootstrap
- server_init.go: buildMiddleware, resolveActiveNetworks, newX402Server,
  persistSettlement, sendSettlementWebhook (deduplicate settleHook)
- server.go: New 120 -> 32 lines, grouped Server fields by
  Transport/Dependencies/Cache/Payments, keep struct compat for tests
- verified: gofmt clean, go build/vet pass, go test ./... pass
2026-09-03 23:59:16 +00:00
3c024d668e Add observability, post caching, dedup, Bluesky refresh, Twitter backoff, MCP tests
- Per-tool Prometheus-style metrics via /metrics and error logging on failures
- In-memory TTL post cache for getPost/getLatestPosts/getPostsInTime/getFeed
- searchActors dedupes cross-platform duplicates by normalized handle
- Bluesky client refreshes session on auth/expired-token errors (retry once)
- Twitter client backs off on HTTP 429 honoring Retry-After
- MCP tests with fake platform backends (dispatch, caching, dedup, partial/full failure)

Co-Authored-By: Claude (AI assistant) <noreply@anthropic.com>
2026-08-29 02:46:17 +02:00