mirror of https://github.com/AMT-Cheif/drift.git
parent
8bed506e0d
commit
7a44224370
|
@ -10,7 +10,7 @@ const _listEquality = ListEquality<dynamic>();
|
||||||
/// statement is reading its data and how to execute the query.
|
/// statement is reading its data and how to execute the query.
|
||||||
class QueryStreamFetcher<T> {
|
class QueryStreamFetcher<T> {
|
||||||
/// The set of tables this query reads from. If any of these tables changes,
|
/// The set of tables this query reads from. If any of these tables changes,
|
||||||
/// the stream must fetch its again.
|
/// the stream must fetch its data again.
|
||||||
final Set<TableInfo> readsFrom;
|
final Set<TableInfo> readsFrom;
|
||||||
|
|
||||||
/// Key that can be used to check whether two fetchers will yield the same
|
/// Key that can be used to check whether two fetchers will yield the same
|
||||||
|
@ -89,8 +89,13 @@ class StreamQueryStore {
|
||||||
/// from that table.
|
/// from that table.
|
||||||
Future<void> handleTableUpdates(Set<TableInfo> tables) async {
|
Future<void> handleTableUpdates(Set<TableInfo> tables) async {
|
||||||
final activeStreams = List<QueryStream>.from(_activeStreams);
|
final activeStreams = List<QueryStream>.from(_activeStreams);
|
||||||
final affectedStreams = activeStreams
|
final updatedNames = tables.map((t) => t.actualTableName).toSet();
|
||||||
.where((stream) => stream._fetcher.readsFrom.any(tables.contains));
|
|
||||||
|
final affectedStreams = activeStreams.where((stream) {
|
||||||
|
return stream._fetcher.readsFrom.any((table) {
|
||||||
|
return updatedNames.contains(table.actualTableName);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
for (var stream in affectedStreams) {
|
for (var stream in affectedStreams) {
|
||||||
await stream.fetchAndEmitData();
|
await stream.fetchAndEmitData();
|
||||||
|
|
|
@ -32,6 +32,17 @@ void main() {
|
||||||
verify(executor.runSelect(any, any)).called(2);
|
verify(executor.runSelect(any, any)).called(2);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('streams recognize aliased tables', () {
|
||||||
|
final first = db.alias(db.users, 'one');
|
||||||
|
final second = db.alias(db.users, 'two');
|
||||||
|
|
||||||
|
db.select(first).watch().listen((_) {});
|
||||||
|
|
||||||
|
db.markTablesUpdated({second});
|
||||||
|
|
||||||
|
verify(executor.runSelect(any, any)).called(2);
|
||||||
|
});
|
||||||
|
|
||||||
test('equal statements yield identical streams', () {
|
test('equal statements yield identical streams', () {
|
||||||
final firstStream = (db.select(db.users).watch())..listen((_) {});
|
final firstStream = (db.select(db.users).watch())..listen((_) {});
|
||||||
final secondStream = (db.select(db.users).watch())..listen((_) {});
|
final secondStream = (db.select(db.users).watch())..listen((_) {});
|
||||||
|
|
Loading…
Reference in New Issue