Skip to content

Commit 443fbde

Browse files
committed
Don't use transactions by default for internal SDK calls
1 parent b064000 commit 443fbde

File tree

5 files changed

+24
-6
lines changed

5 files changed

+24
-6
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
# Parse-Swift Changelog
22

33
### main
4-
[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/1.8.0...main)
4+
[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/1.8.1...main)
55
* _Contributing to this repo? Add info about your change here to be included in the next release_
66

7+
### 1.8.0
8+
[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/1.8.0...1.8.1)
9+
710
__Improvements__
811
- Append instead of replace when using query select, exclude, include, and fields ([#155](https://github.com/parse-community/Parse-Swift/pull/155)), thanks to [Corey Baker](https://github.com/cbaker6).
912

13+
__Fixes__
14+
- Transactions currently don't work when using mongoDB(postgres does work) on the parse-server. Internal use of transactions are disabled by default. If you want the Swift SDK to use transactions internally, you need to set useTransactionsInternally=true when configuring the client. It is recommended not to use transactions if you are using mongoDB until it's fixed on the server ([#158](https://github.com/parse-community/Parse-Swift/pull/158)), thanks to [Corey Baker](https://github.com/cbaker6).
15+
1016
### 1.8.0
1117
[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/1.7.2...1.8.0)
1218

ParseSwift.playground/Pages/1 - Your first Object.xcplaygroundpage/Contents.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ var score2ForFetchedLater: GameScore?
114114
}
115115

116116
//: Saving multiple GameScores at once using a transaction.
117-
[score, score2].saveAll(transaction: true) { results in
117+
//: Currently doesn't work on mongo
118+
/*[score, score2].saveAll(transaction: true) { results in
118119
switch results {
119120
case .success(let otherResults):
120121
var index = 0
@@ -134,7 +135,7 @@ var score2ForFetchedLater: GameScore?
134135
case .failure(let error):
135136
assertionFailure("Error saving: \(error)")
136137
}
137-
}
138+
}*/
138139

139140
//: Save synchronously (not preferred - all operations on main queue).
140141
let savedScore: GameScore?
@@ -270,7 +271,7 @@ do {
270271
}
271272

272273
//: Asynchronously (preferred way) deleteAll GameScores based on it's objectId alone.
273-
[scoreToFetch, score2ToFetch].deleteAll(transaction: true) { result in
274+
[scoreToFetch, score2ToFetch].deleteAll { result in
274275
switch result {
275276
case .success(let deletedScores):
276277
deletedScores.forEach { result in

ParseSwift.playground/Sources/Common.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ public func initializeParse() {
55
ParseSwift.initialize(applicationId: "applicationId",
66
clientKey: "clientKey",
77
masterKey: "masterKey",
8-
serverURL: URL(string: "http://localhost:1337/1")!)
8+
serverURL: URL(string: "http://localhost:1337/1")!,
9+
useTransactionsInternally: false)
910
}
1011

1112
public func initializeParseCustomObjectId() {

Sources/ParseSwift/Objects/ParseObject.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,7 @@ extension ParseObject {
725725
// MARK: Savable Encodable Version
726726
internal extension ParseType {
727727
func saveAll(objects: [ParseType],
728-
transaction: Bool = true,
728+
transaction: Bool = ParseSwift.configuration.useTransactionsInternally,
729729
options: API.Options = []) throws -> [(Result<PointerType, ParseError>)] {
730730
try API.NonParseBodyCommand<AnyCodable, PointerType>
731731
.batch(objects: objects,

Sources/ParseSwift/Parse.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ public struct ParseConfiguration {
2626
/// Allows objectIds to be created on the client.
2727
var allowCustomObjectId = false
2828

29+
/// Use transactions inside the Client SDK.
30+
/// - warning: This is experimental and known not to work with mongoDB.
31+
var useTransactionsInternally = false
32+
2933
internal var authentication: ((URLAuthenticationChallenge,
3034
(URLSession.AuthChallengeDisposition,
3135
URLCredential?) -> Void) -> Void)?
@@ -57,6 +61,7 @@ public struct ParseConfiguration {
5761
serverURL: URL,
5862
liveQueryServerURL: URL? = nil,
5963
allowCustomObjectId: Bool = false,
64+
useTransactionsInternally: Bool = false,
6065
keyValueStore: ParseKeyValueStore? = nil,
6166
authentication: ((URLAuthenticationChallenge,
6267
(URLSession.AuthChallengeDisposition,
@@ -67,6 +72,7 @@ public struct ParseConfiguration {
6772
self.serverURL = serverURL
6873
self.liveQuerysServerURL = liveQueryServerURL
6974
self.allowCustomObjectId = allowCustomObjectId
75+
self.useTransactionsInternally = useTransactionsInternally
7076
self.mountPath = "/" + serverURL.pathComponents
7177
.filter { $0 != "/" }
7278
.joined(separator: "/")
@@ -153,6 +159,7 @@ public struct ParseSwift {
153159
serverURL: URL,
154160
liveQueryServerURL: URL? = nil,
155161
allowCustomObjectId: Bool = false,
162+
useTransactionsInternally: Bool = false,
156163
keyValueStore: ParseKeyValueStore? = nil,
157164
migrateFromObjcSDK: Bool = false,
158165
authentication: ((URLAuthenticationChallenge,
@@ -165,6 +172,7 @@ public struct ParseSwift {
165172
serverURL: serverURL,
166173
liveQueryServerURL: liveQueryServerURL,
167174
allowCustomObjectId: allowCustomObjectId,
175+
useTransactionsInternally: useTransactionsInternally,
168176
keyValueStore: keyValueStore,
169177
authentication: authentication),
170178
migrateFromObjcSDK: migrateFromObjcSDK)
@@ -176,6 +184,7 @@ public struct ParseSwift {
176184
serverURL: URL,
177185
liveQueryServerURL: URL? = nil,
178186
allowCustomObjectId: Bool = false,
187+
useTransactionsInternally: Bool = false,
179188
keyValueStore: ParseKeyValueStore? = nil,
180189
migrateFromObjcSDK: Bool = false,
181190
testing: Bool = false,
@@ -188,6 +197,7 @@ public struct ParseSwift {
188197
serverURL: serverURL,
189198
liveQueryServerURL: liveQueryServerURL,
190199
allowCustomObjectId: allowCustomObjectId,
200+
useTransactionsInternally: useTransactionsInternally,
191201
keyValueStore: keyValueStore,
192202
authentication: authentication),
193203
migrateFromObjcSDK: migrateFromObjcSDK)

0 commit comments

Comments
 (0)