feat(session): query enabled sources before providers (#85)

UserSessionManager now queries the user_sources table for enabled
sources before calling any provider. Providers receive the per-user
JSON config directly instead of querying the DB themselves, removing
their db dependency and eliminating redundant round-trips.

Co-authored-by: Ona <no-reply@ona.com>
This commit is contained in:
2026-03-22 16:28:19 +00:00
committed by GitHub
parent b24d879d31
commit a6be7b31e7
13 changed files with 368 additions and 200 deletions

View File

@@ -1,7 +1,6 @@
import { FeedEngine, type FeedItem, type FeedResult, type FeedSource } from "@aelis/core"
import type { FeedEnhancer } from "../enhancement/enhance-feed.ts"
import type { FeedSourceProvider } from "./feed-source-provider.ts"
export class UserSession {
readonly userId: string
@@ -70,25 +69,8 @@ export class UserSession {
return this.sources.get(sourceId) as T | undefined
}
/**
* Re-resolves a source from its provider using this session's userId.
* The source must already be registered. Throws if it isn't.
* If the provider fails, the existing source is kept.
*/
async refreshSource(provider: FeedSourceProvider): Promise<void> {
if (!this.sources.has(provider.sourceId)) {
throw new Error(`Cannot refresh source "${provider.sourceId}": not registered`)
}
try {
const newSource = await provider.feedSourceForUser(this.userId)
this.replaceSource(provider.sourceId, newSource)
} catch (err) {
console.error(
`[UserSession] refreshSource("${provider.sourceId}") failed for user ${this.userId}:`,
err,
)
}
hasSource(sourceId: string): boolean {
return this.sources.has(sourceId)
}
/**