From 449c243a361c0e66213bb4038614eb9d2afdcae6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sat, 18 Mar 2023 11:08:56 +0100 Subject: [PATCH] Rename persistentReaderConnections to dbConfiguration.persistentReadOnlyConnections --- GRDB/Core/Configuration.swift | 26 +++++++------------ GRDB/Core/DatabasePool.swift | 16 ++++++------ .../Extension/Configuration.md | 2 +- .../DatabasePoolReleaseMemoryTests.swift | 8 +++--- 4 files changed, 23 insertions(+), 29 deletions(-) diff --git a/GRDB/Core/Configuration.swift b/GRDB/Core/Configuration.swift index f2868d108..495b32690 100644 --- a/GRDB/Core/Configuration.swift +++ b/GRDB/Core/Configuration.swift @@ -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 diff --git a/GRDB/Core/DatabasePool.swift b/GRDB/Core/DatabasePool.swift index b08a13906..a19baf918 100644 --- a/GRDB/Core/DatabasePool.swift +++ b/GRDB/Core/DatabasePool.swift @@ -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() diff --git a/GRDB/Documentation.docc/Extension/Configuration.md b/GRDB/Documentation.docc/Extension/Configuration.md index aaf64e58f..e2e4b2743 100644 --- a/GRDB/Documentation.docc/Extension/Configuration.md +++ b/GRDB/Documentation.docc/Extension/Configuration.md @@ -92,7 +92,7 @@ do { - ``label`` - ``maximumReaderCount`` - ``observesSuspensionNotifications`` -- ``persistentReaderConnections`` +- ``persistentReadOnlyConnections`` - ``prepareDatabase(_:)`` - ``publicStatementArguments`` - ``transactionClock`` diff --git a/Tests/GRDBTests/DatabasePoolReleaseMemoryTests.swift b/Tests/GRDBTests/DatabasePoolReleaseMemoryTests.swift index 31e26faa8..9b6bb306c 100644 --- a/Tests/GRDBTests/DatabasePoolReleaseMemoryTests.swift +++ b/Tests/GRDBTests/DatabasePoolReleaseMemoryTests.swift @@ -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