refactor: centralize conversation cache management

- Introduced a new method `refreshConversationsCache` to streamline the invalidation of the conversations provider and optionally the folders provider.
- Updated various components to utilize the new cache management method, enhancing code clarity and reducing redundancy.
- This refactor improves the efficiency of conversation and folder synchronization across the application.
This commit is contained in:
cogwheel0
2025-10-02 00:30:14 +05:30
parent 73ccb14b20
commit ff02af1e89
7 changed files with 122 additions and 68 deletions

View File

@@ -661,6 +661,17 @@ class _ConversationsCacheTimestamp extends _$ConversationsCacheTimestamp {
void set(DateTime? timestamp) => state = timestamp;
}
/// Clears the in-memory timestamp cache and invalidates the conversations
/// provider so the next read forces a refetch. Optionally invalidates the
/// folders provider when folder metadata must stay in sync with conversations.
void refreshConversationsCache(dynamic ref, {bool includeFolders = false}) {
ref.read(_conversationsCacheTimestampProvider.notifier).set(null);
ref.invalidate(conversationsProvider);
if (includeFolders) {
ref.invalidate(foldersProvider);
}
}
// Conversation providers - Now using correct OpenWebUI API with caching
// keepAlive to maintain cache during authenticated session
@Riverpod(keepAlive: true)

View File

@@ -103,7 +103,7 @@ void _scheduleConversationWarmup(Ref ref, {bool force = false}) {
return;
}
if (existing.hasError) {
ref.invalidate(conversationsProvider);
refreshConversationsCache(ref);
}
final conversations = await ref.read(conversationsProvider.future);
statusController.set(_ConversationWarmupStatus.complete);
@@ -368,7 +368,7 @@ class _ForegroundRefreshObserver extends WidgetsBindingObserver {
// Schedule to avoid side-effects during build frames
Future.microtask(() {
try {
_ref.invalidate(conversationsProvider);
refreshConversationsCache(_ref);
_ref
.read(_conversationWarmupStatusProvider.notifier)
.set(_ConversationWarmupStatus.idle);