Rename persistentReaderConnections to dbConfiguration.persistentReadOnlyConnections

This commit is contained in:
Gwendal Roué committed 2023-03-18 11:08:56 +01:00
1 parent 6ca4986bc2
commit 449c243a36
4 files changed
+23 -29

No files matched your search

+10 -16
View File
@@ -374,25 +374,19 @@ public struct Configuration {
#endif
/// A boolean value indicating whether read-only connections should be
/// kept open as long as they remain in a valid state.
/// kept open.
///
/// This configuration applies to ``DatabasePool`` only. The default value
/// is false.
/// This configuration flag applies to ``DatabasePool`` only. The
/// default value is false.
///
/// A `DatabasePool` automatically closes read-only connections on
/// various occasions, in order to spare memory
/// (see ``DatabasePool/releaseMemory()``), or when connections enter an
/// invalid state.
/// When the flag is false, a `DatabasePool` closes read-only
/// connections when requested to dispose non-essential memory with
/// ``DatabasePool/releaseMemory()``. When true, those connections are
/// kept open.
///
/// When this flag is true, only invalid connections are automatically
/// closed. Valid connections, once opened, are kept alive until the
/// `DatabasePool` is deinitialized, or one of those methods is called:
/// ``DatabaseReader/close()``,
/// ``DatabasePool/invalidateReadOnlyConnections()``.
///
/// Consider using this flag when profiling your application reveals
/// that a lot of time is spent opening new SQLite connections.
public var persistentReaderConnections = false
/// Consider setting this flag to true when profiling your application
/// reveals that a lot of time is spent opening new SQLite connections.
public var persistentReadOnlyConnections = false
// MARK: - Factory Configuration
+8 -8
View File
@@ -173,8 +173,8 @@ extension DatabasePool {
/// This method is synchronous, and blocks the current thread until all
/// database accesses are completed.
///
/// This method closes all reader connections, unless the
/// ``Configuration/persistentReaderConnections`` configuration flag
/// This method closes all read-only connections, unless the
/// ``Configuration/persistentReadOnlyConnections`` configuration flag
/// is set.
///
/// - warning: This method can prevent concurrent reads from executing,
@@ -184,7 +184,7 @@ extension DatabasePool {
// Release writer memory
writer.sync { $0.releaseMemory() }
if configuration.persistentReaderConnections {
if configuration.persistentReadOnlyConnections {
// Keep existing readers
readerPool?.forEach { reader in
reader.sync { $0.releaseMemory() }
@@ -207,15 +207,15 @@ extension DatabasePool {
/// Eventually frees as much memory as possible, by disposing
/// non-essential memory.
///
/// This method eventually closes all reader connections, unless the
/// ``Configuration/persistentReaderConnections`` configuration flag
/// This method eventually closes all read-only connections, unless the
/// ``Configuration/persistentReadOnlyConnections`` configuration flag
/// is set.
///
/// Unlike ``releaseMemory()``, this method does not prevent concurrent
/// database accesses when it is executing. But it does not notify when
/// non-essential memory has been freed.
public func releaseMemoryEventually() {
if configuration.persistentReaderConnections {
if configuration.persistentReadOnlyConnections {
// Keep existing readers
readerPool?.forEach { reader in
reader.async { $0.releaseMemory() }
@@ -627,11 +627,11 @@ extension DatabasePool: DatabaseReader {
/// After this method is called, read-only database access methods will use
/// new SQLite connections.
///
/// Eventual concurrent read-only accesses are not invalidated: they will
/// Eventual concurrent read-only accesses are not interrupted, and
/// proceed until completion.
///
/// - This method closes all read-only connections, even if the
/// ``Configuration/persistentReaderConnections`` configuration flag
/// ``Configuration/persistentReadOnlyConnections`` configuration flag
/// is set.
public func invalidateReadOnlyConnections() {
readerPool?.removeAll()
@@ -92,7 +92,7 @@ do {
- ``label``
- ``maximumReaderCount``
- ``observesSuspensionNotifications``
- ``persistentReaderConnections``
- ``persistentReadOnlyConnections``
- ``prepareDatabase(_:)``
- ``publicStatementArguments``
- ``transactionClock``
@@ -198,7 +198,7 @@ class DatabasePoolReleaseMemoryTests: GRDBTestCase {
XCTAssertEqual(openConnectionCount, 1)
}
func test_DatabasePool_releaseMemory_closes_reader_connections_when_persistentReaderConnections_is_false() throws {
func test_DatabasePool_releaseMemory_closes_reader_connections_when_persistentReadOnlyConnections_is_false() throws {
var persistentConnectionCount = 0
dbConfiguration.SQLiteConnectionDidOpen = {
@@ -209,7 +209,7 @@ class DatabasePoolReleaseMemoryTests: GRDBTestCase {
persistentConnectionCount -= 1
}
dbConfiguration.persistentReaderConnections = false
dbConfiguration.persistentReadOnlyConnections = false
let dbPool = try makeDatabasePool()
XCTAssertEqual(persistentConnectionCount, 1) // writer
@@ -221,7 +221,7 @@ class DatabasePoolReleaseMemoryTests: GRDBTestCase {
XCTAssertEqual(persistentConnectionCount, 1) // writer
}
func test_DatabasePool_releaseMemory_does_not_close_reader_connections_when_persistentReaderConnections_is_true() throws {
func test_DatabasePool_releaseMemory_does_not_close_reader_connections_when_persistentReadOnlyConnections_is_true() throws {
var persistentConnectionCount = 0
dbConfiguration.SQLiteConnectionDidOpen = {
@@ -232,7 +232,7 @@ class DatabasePoolReleaseMemoryTests: GRDBTestCase {
persistentConnectionCount -= 1
}
dbConfiguration.persistentReaderConnections = true
dbConfiguration.persistentReadOnlyConnections = true
let dbPool = try makeDatabasePool()
XCTAssertEqual(persistentConnectionCount, 1) // writer