refactor: shared coalescer, profile-scoped prefs key, and form-error helper
This commit is contained in:
@@ -96,12 +96,12 @@ class StorageService extends BaseSharedPreferencesService {
|
||||
/// full profile id is the scope.
|
||||
String? activeUserScope() => _activeUserScope();
|
||||
|
||||
String userScopeForProfileId(String profileId) => parsePlexHomeProfileId(profileId)?.homeUserUuid ?? profileId;
|
||||
String userScopeForProfileId(String profileId) => profileUserScope(profileId);
|
||||
|
||||
String? _activeUserScope() {
|
||||
final id = getActiveProfileId();
|
||||
if (id == null) return null;
|
||||
return parsePlexHomeProfileId(id)?.homeUserUuid ?? id;
|
||||
return profileUserScope(id);
|
||||
}
|
||||
|
||||
/// Returns `'user_{scope}_'` for the active profile, or `''` if no
|
||||
|
||||
@@ -12,4 +12,30 @@ class FutureCoalescer<T> {
|
||||
_inFlight = future;
|
||||
return future;
|
||||
}
|
||||
|
||||
/// Detach the in-flight future (it keeps running, but the next [run]
|
||||
/// starts fresh instead of joining it). The identical-guard above keeps
|
||||
/// the detached future's completion from clearing a newer slot.
|
||||
void reset() {
|
||||
_inFlight = null;
|
||||
}
|
||||
}
|
||||
|
||||
/// Keyed [FutureCoalescer]: one in-flight future per key. Used for the
|
||||
/// static per-identity re-auth/refresh maps (Trakt refresh-by-token, Seerr
|
||||
/// re-auth-by-instance) so concurrent 401s trigger one login each.
|
||||
class KeyedFutureCoalescer<K, T> {
|
||||
final Map<K, Future<T>> _inFlight = {};
|
||||
|
||||
Future<T> run(K key, Future<T> Function() create) {
|
||||
final existing = _inFlight[key];
|
||||
if (existing != null) return existing;
|
||||
|
||||
late final Future<T> future;
|
||||
future = create().whenComplete(() {
|
||||
if (identical(_inFlight[key], future)) _inFlight.remove(key);
|
||||
});
|
||||
_inFlight[key] = future;
|
||||
return future;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import '../../profiles/profile.dart';
|
||||
import '../base_shared_preferences_service.dart';
|
||||
import 'tracker_constants.dart';
|
||||
import 'tracker_session.dart';
|
||||
@@ -25,7 +26,7 @@ class TrackerAccountStore {
|
||||
|
||||
TrackerAccountStore._(this.service, this._baseKey);
|
||||
|
||||
String _scopedKey(String userUuid) => userUuid.isEmpty ? _baseKey : 'user_${userUuid}_$_baseKey';
|
||||
String _scopedKey(String userUuid) => profileScopedPrefsKey(userUuid, _baseKey);
|
||||
|
||||
Future<TrackerSession?> load(String userUuid) async {
|
||||
final prefs = await BaseSharedPreferencesService.sharedCache();
|
||||
|
||||
Reference in New Issue
Block a user