Key subscription providers by account rather than backend type

SubscriptionService held one provider per backend and each resolved its
instance from settingsManager.subscriptionAccount, falling back to "the
first enabled Invidious instance" when that was unset. With several logins
possible on one instance that model breaks twice: two accounts would share
a single in-memory subscription cache, and the fallback could send an
account's request to a server it holds no credential for.

Providers are now built per account and cached by account ID, and each
resolves its instance and credential from the account it was built for -
no fallback. The protocol's accountType becomes a DataContext, which is
what actually identifies a provider now.

Views that branched on "is the subscription account local" read the context
instead, and the settings picker writes both stores. Keeping the legacy
setting in step is deliberate for now: several views still read it, and
letting the two diverge would show one account in the UI while serving
another's data. The Phase 3 switcher removes the last readers.

Signing out discards the account's provider so its cached subscriptions
cannot be served after the account is gone.
This commit is contained in:
Arkadiusz Fal
2026-08-24 23:56:40 +02:00
parent 66f721e3ac
commit 9065234606
10 changed files with 120 additions and 77 deletions

View File

@@ -1315,7 +1315,7 @@ struct SubscriptionsView: View {
private func loadSubscriptions() {
// For local account, load from DataManager
// For Invidious, subscriptions will be loaded async in loadSubscriptionsAsync
if appEnvironment?.settingsManager.subscriptionAccount.type == .local {
if appEnvironment?.accountsManager.currentContext.isLocal == true {
subscriptions = dataManager?.subscriptions() ?? []
subscriptionsLoaded = true
sidebarExpected = subscriptions.count > 1
@@ -1333,7 +1333,7 @@ struct SubscriptionsView: View {
guard let subscriptionService, let appEnvironment else { return }
// For local account, just load from DataManager (fast)
if appEnvironment.settingsManager.subscriptionAccount.type == .local {
if appEnvironment.accountsManager.currentContext.isLocal {
subscriptions = dataManager?.subscriptions() ?? []
subscriptionsLoaded = true
sidebarExpected = subscriptions.count > 1