Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Changelog

## Unreleased
## 1.16.1

* Fix a re-query storm on databases opened at an absolute path (App Group container). The
cross-process change notification carried no payload, so every process (including the one
Expand All @@ -9,6 +9,7 @@
permanent loop that pinned the CPU. Processes now exchange the concrete changed tables
through a local `ps_swift_updates` table, so each process ignores its own changes and only
wakes the queries whose tables actually changed.
* Update PowerSync SQLite core extension to version 0.5.3, improving internal error messages.

## 1.16.0

Expand Down
6 changes: 3 additions & 3 deletions Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ if let corePath = localCoreExtension {
conditionalDependencies.append(
.package(
url: "https://github.com/powersync-ja/powersync-sqlite-core-swift.git",
exact: "0.5.2",
exact: "0.5.3",
))
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/PowerSync/CurrentVersion.swift
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// The current version of the PowerSync Swift SDK. This should be updated to the latest version in `CHANGELOG.md` when a new version is released.
let libraryVersion = "1.16.0"
let libraryVersion = "1.16.1"
11 changes: 9 additions & 2 deletions Sources/PowerSync/Implementation/AsyncConnectionPool.swift
Original file line number Diff line number Diff line change
Expand Up @@ -233,14 +233,21 @@ final class AsyncConnectionPool: SQLiteConnectionPoolProtocol {
func write<T>(onConnection: @escaping @Sendable (any SQLiteConnectionLease) throws -> T) async throws -> T {
let pool = try await obtainInner()
return try await pool.write { connection in
try await runBlocking { try onConnection(connection) }
try await runBlocking {
defer { pool.dispatchWrites(lease: connection) }
return try onConnection(connection)
}
}
}

func withAllConnections<T>(onConnection: @escaping @Sendable (any SQLiteConnectionLease, [any SQLiteConnectionLease]) throws -> T) async throws -> T {
let pool = try await obtainInner()
return try await pool.withAllConnections { writer, readers in
try await runBlocking { try onConnection(writer, readers) }
try await runBlocking {
defer { pool.dispatchWrites(lease: writer) }

return try onConnection(writer, readers)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ final class NativeConnectionPool: Sendable {
self.updateLog = updateLog
}

private func dispatchWrites(lease: NativeConnectionLease) {
/// Reads outstanding changes and records them for other processes.
///
/// Recording them for other processes might write, so this should be called on a background thread only.
func dispatchWrites(lease: NativeConnectionLease) {
do {
try lease.withIterator(sql: "SELECT powersync_update_hooks('get')", parameters: []) { rows in
guard var affectedTables = try rows.next(callback: {
Expand Down Expand Up @@ -79,15 +82,13 @@ final class NativeConnectionPool: Sendable {
func write<T>(onConnection: (NativeConnectionLease) async throws -> T) async throws -> T {
let connection = try await writer.acquire(count: 1)
let lease = try connection.acquiredItems[0].asLease()
defer { dispatchWrites(lease: lease) }
let result = try await onConnection(lease)
return result
}

func withAllConnections<T>(onConnection: (NativeConnectionLease, [NativeConnectionLease]) async throws -> T) async throws -> T {
let write = try await writer.acquire(count: 1)
let writeLease = try write.acquiredItems[0].asLease()
defer { dispatchWrites(lease: writeLease) }

let result: T
if let readers {
Expand Down