mirror of
https://github.com/kennethnym/aris.git
synced 2026-03-24 02:51:17 +00:00
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:
@@ -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)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user