Skip to content

Commit fb18a39

Browse files
committed
Database.isolated(readOnly: true) avoids triggering database observation
Fix failing test for groue#1209
1 parent 5082207 commit fb18a39

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

GRDB/Core/Database.swift

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,13 +1018,20 @@ public final class Database: CustomStringConvertible, CustomDebugStringConvertib
10181018
/// - parameter readOnly: If true, writes are forbidden.
10191019
func isolated<T>(readOnly: Bool = false, _ block: () throws -> T) throws -> T {
10201020
var result: T?
1021-
try inSavepoint {
1022-
if readOnly {
1023-
result = try self.readOnly(block)
1024-
} else {
1021+
if readOnly {
1022+
// Enter read-only mode before starting a transaction, so that the
1023+
// transaction commit does not trigger database observation.
1024+
try self.readOnly {
1025+
try inSavepoint {
1026+
result = try block()
1027+
return .commit
1028+
}
1029+
}
1030+
} else {
1031+
try inSavepoint {
10251032
result = try block()
1033+
return .commit
10261034
}
1027-
return .commit
10281035
}
10291036
return result!
10301037
}

0 commit comments

Comments
 (0)