Skip to content

Commit

Permalink
Transaction logging should happen before opening transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
cedrickcooke committed Sep 5, 2024
1 parent 58f36af commit df369bc
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions core/src/jsMain/kotlin/Database.kt
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public suspend fun openDatabase(
"Upgrading database `$name` from version `${versionChangeEvent.oldVersion}` to `${versionChangeEvent.newVersion}`"
}
val id = database.transactionId++
logger.log(Type.Transaction) { "Opened versionchange transaction $id on database `$name`" }
logger.log(Type.Transaction) { "Opening versionchange transaction $id on database `$name`" }
val transaction = VersionChangeTransaction(checkNotNull(request.transaction), logger, id)
transaction.initialize(database, versionChangeEvent.oldVersion, versionChangeEvent.newVersion)
transaction.awaitCompletion { event ->
Expand Down Expand Up @@ -109,15 +109,15 @@ public class Database internal constructor(
action: suspend Transaction.() -> T,
): T = withContext(Dispatchers.Unconfined) {
val id = transactionId++
logger.log(Type.Transaction) {
"Opened readonly transaction $id using stores ${store.joinToString { "`$it`" }} on database `$name`"
}

val transaction = Transaction(
ensureDatabase().transaction(arrayOf(*store), "readonly", transactionOptions(durability)),
logger,
id,
)

logger.log(Type.Transaction) {
"Opened readonly transaction $id using stores ${store.joinToString { "`$it`" }} on database `$name`"
}
val result = transaction.action()
transaction.awaitCompletion { event ->
logger.log(Type.Transaction, event) { "Closed readonly transaction $id on database `$name`" }
Expand All @@ -137,6 +137,10 @@ public class Database internal constructor(
action: suspend WriteTransaction.() -> T,
): T = withContext(Dispatchers.Unconfined) {
val id = transactionId++
logger.log(Type.Transaction) {
"Opening readwrite transaction $id using stores ${store.joinToString { "`$it`" }} on database `$name`"
}

val transaction = WriteTransaction(
ensureDatabase().transaction(arrayOf(*store), "readwrite", transactionOptions(durability)),
logger,
Expand All @@ -146,10 +150,6 @@ public class Database internal constructor(
// Force overlapping transactions to not call `action` until prior transactions complete.
objectStore(store.first()).awaitTransaction()
}

logger.log(Type.Transaction) {
"Opened readwrite transaction $id using stores ${store.joinToString { "`$it`" }} on database `$name`"
}
val result = transaction.action()
transaction.awaitCompletion { event ->
logger.log(Type.Transaction, event) { "Closed readwrite transaction $id on database `$name`" }
Expand Down

0 comments on commit df369bc

Please sign in to comment.