fix: persistence (#329)
* fix(llc): Save original passed persistence for client reconnection. Signed-off-by: Sahil Kumar <[email protected]> * fix(persistence): Check for empty channels before applying offset Signed-off-by: Sahil Kumar <[email protected]> * fix(llc): Remove debug logs Signed-off-by: Sahil Kumar <[email protected]> * fix(persistence): Reset isolate on successful disconnect Signed-off-by: Sahil Kumar <[email protected]> * use mutexes in persistence client * fix(persistence): use `super.updateChannelStates` Signed-off-by: Sahil Kumar <[email protected]> * fix(persistence): fix database multiple times creation. Signed-off-by: Sahil Kumar <[email protected]> Co-authored-by: Sahil Kumar <[email protected]>
This commit is contained in:
co-authored by
Sahil Kumar
parent
ca1f70948e
commit
9952265109
@@ -6,6 +6,7 @@ import 'package:stream_chat_persistence/src/db/moor_chat_database.dart';
|
||||
import 'package:stream_chat_persistence/src/entity/channel_queries.dart';
|
||||
import 'package:stream_chat_persistence/src/entity/channels.dart';
|
||||
import 'package:stream_chat_persistence/src/entity/users.dart';
|
||||
|
||||
import '../mapper/mapper.dart';
|
||||
|
||||
part 'channel_query_dao.g.dart';
|
||||
@@ -33,24 +34,26 @@ class ChannelQueryDao extends DatabaseAccessor<MoorChatDatabase>
|
||||
List<String> cids,
|
||||
bool clearQueryCache,
|
||||
) async {
|
||||
final hash = _computeHash(filter);
|
||||
if (clearQueryCache) {
|
||||
return transaction(() async {
|
||||
final hash = _computeHash(filter);
|
||||
if (clearQueryCache) {
|
||||
await batch((it) {
|
||||
it.deleteWhere<ChannelQueries, ChannelQueryEntity>(
|
||||
channelQueries,
|
||||
(c) => c.queryHash.equals(hash),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
await batch((it) {
|
||||
it.deleteWhere<ChannelQueries, ChannelQueryEntity>(
|
||||
it.insertAll(
|
||||
channelQueries,
|
||||
(c) => c.queryHash.equals(hash),
|
||||
cids.map((cid) {
|
||||
return ChannelQueryEntity(queryHash: hash, channelCid: cid);
|
||||
}).toList(),
|
||||
mode: InsertMode.insertOrReplace,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
return batch((it) {
|
||||
it.insertAll(
|
||||
channelQueries,
|
||||
cids.map((cid) {
|
||||
return ChannelQueryEntity(queryHash: hash, channelCid: cid);
|
||||
}).toList(),
|
||||
mode: InsertMode.insertOrReplace,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -117,7 +120,7 @@ class ChannelQueryDao extends DatabaseAccessor<MoorChatDatabase>
|
||||
|
||||
cachedChannels.sort(chainedComparator);
|
||||
|
||||
if (paginationParams?.offset != null) {
|
||||
if (paginationParams?.offset != null && cachedChannels.isNotEmpty) {
|
||||
cachedChannels.removeRange(0, paginationParams.offset);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ import 'package:stream_chat/stream_chat.dart';
|
||||
import 'package:stream_chat_persistence/src/db/moor_chat_database.dart';
|
||||
import 'package:stream_chat_persistence/src/entity/connection_events.dart';
|
||||
import 'package:stream_chat_persistence/src/entity/users.dart';
|
||||
|
||||
import '../mapper/mapper.dart';
|
||||
|
||||
part 'connection_event_dao.g.dart';
|
||||
@@ -27,20 +28,23 @@ class ConnectionEventDao extends DatabaseAccessor<MoorChatDatabase>
|
||||
}
|
||||
|
||||
/// Update stored connection event with latest data
|
||||
Future<int> updateConnectionEvent(Event event) async {
|
||||
final connectionInfo = await select(connectionEvents).getSingle();
|
||||
return into(connectionEvents).insert(
|
||||
ConnectionEventEntity(
|
||||
id: 1,
|
||||
lastSyncAt: connectionInfo?.lastSyncAt,
|
||||
lastEventAt: event.createdAt ?? connectionInfo?.lastEventAt,
|
||||
totalUnreadCount:
|
||||
event.totalUnreadCount ?? connectionInfo?.totalUnreadCount,
|
||||
ownUser: event.me?.toJson() ?? connectionInfo?.ownUser,
|
||||
unreadChannels: event.unreadChannels ?? connectionInfo?.unreadChannels,
|
||||
),
|
||||
mode: InsertMode.insertOrReplace,
|
||||
);
|
||||
Future<void> updateConnectionEvent(Event event) async {
|
||||
return transaction(() async {
|
||||
final connectionInfo = await select(connectionEvents).getSingle();
|
||||
await into(connectionEvents).insert(
|
||||
ConnectionEventEntity(
|
||||
id: 1,
|
||||
lastSyncAt: connectionInfo?.lastSyncAt,
|
||||
lastEventAt: event.createdAt ?? connectionInfo?.lastEventAt,
|
||||
totalUnreadCount:
|
||||
event.totalUnreadCount ?? connectionInfo?.totalUnreadCount,
|
||||
ownUser: event.me?.toJson() ?? connectionInfo?.ownUser,
|
||||
unreadChannels:
|
||||
event.unreadChannels ?? connectionInfo?.unreadChannels,
|
||||
),
|
||||
mode: InsertMode.insertOrReplace,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
/// Update stored lastSyncAt with latest data
|
||||
|
||||
Reference in New Issue
Block a user