Fix testSynchronizedFTS4Observation

This commit is contained in:
Gwendal Roué committed 2019-09-26 08:49:44 +02:00
1 parent 0d961ce48e
commit aa1cfb9020
2 files changed
+27 -7

No files matched your search

+5 -2
View File
@@ -186,8 +186,11 @@ extension DatabaseRegion {
guard let tableRegion = tableRegions[event.tableName] else {
// FTS4 (and maybe other virtual tables) perform unadvertised
// changes. So let's assume the precondition is fulfilled, and
// the region is modified, just in case.
// changes. For example, an "INSERT INTO document ..." statement
// advertises an insertion in the `document` table, but the
// actual change events happen in the `document_content` shadow
// table. When such a non-advertised event happens, assume that
// the region is modified.
// See https://github.com/groue/GRDB.swift/issues/620
return true
}
+22 -5
View File
@@ -283,7 +283,11 @@ class DatabaseObservationBroker {
// observation will only be notified of individual events that
// match one of the observed kinds.
return (observation, DatabaseEventPredicate.matching(observedKinds))
return (
observation,
DatabaseEventPredicate.matching(
observedKinds: observedKinds,
advertisedKinds: eventKinds))
}
}
@@ -1312,15 +1316,28 @@ private struct CopiedDatabasePreUpdateEventImpl: DatabasePreUpdateEventImpl {
enum DatabaseEventPredicate {
// Yes filter
case `true`
// Only events that match one of those kinds
case matching([DatabaseEventKind])
// Only events that match observedKinds
case matching(observedKinds: [DatabaseEventKind], advertisedKinds: [DatabaseEventKind])
func evaluate(_ event: DatabaseEventProtocol) -> Bool {
switch self {
case .true:
return true
case .matching(let kinds):
return kinds.contains { event.matchesKind($0) }
case let .matching(observedKinds: observedKinds, advertisedKinds: advertisedKinds):
if observedKinds.contains(where: { event.matchesKind($0) }) {
return true
}
if !advertisedKinds.contains(where: { event.matchesKind($0) }) {
// FTS4 (and maybe other virtual tables) perform unadvertised
// changes. For example, an "INSERT INTO document ..." statement
// advertises an insertion in the `document` table, but the
// actual change events happen in the `document_content` shadow
// table. When such a non-advertised event happens, assume that
// the event has to be notified.
// See https://github.com/groue/GRDB.swift/issues/620
return true
}
return false
}
}
}