New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for suppressing specific notifications from writes #4253
Conversation
// notification is called (the first would error on .update) | ||
theExpectation = expectation(description: "") | ||
let realm = realmWithTestPath() | ||
realm.beginWrite(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this and the 3 other beginWrite()
s have trailing semicolons
bfccb33
to
b32121c
Compare
Are any of the failing CI jobs relevant? |
The interprocess test failure might be spurious or might be related to these changes. |
@@ -61,7 +61,8 @@ GM seed. | |||
|
|||
### Enhancements | |||
|
|||
* None. | |||
* Add the ability to skip calling specific notification blocks when committing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrong changelog section
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
90e87fb
to
45433f7
Compare
The remaining CI failures here are unrelated (SwiftLint errors are for files not modified in this PR, one job had a test failure that has rarely occurred in the past without these changes, and other two were just the simulator failing to boot). |
There are no SwiftLint errors according to Jenkins: https://ci.realm.io/job/objc_pr/4338/configuration=Release,swift_version=3.0.1,target=swiftlint/console |
@@ -75,6 +76,13 @@ GM seed. | |||
of process termination. | |||
* Fix a crash that could occur when working with a `RLMLinkingObject` property | |||
of an unmanaged object. | |||
* Deliver collection notifications when beginning a write transaction which |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are still in the wrong changelog section though.
The Travis Swiftlint check failed. I assume it's running a different version of swiftlint. |
I see! No, it's actually running with Swift 2.2 whereas Jenkins just runs SwiftLint on 3.0.1. |
d874972
to
33d19aa
Compare
already in a write transaction will throw an exception. Calls to | ||
`beginWriteTransaction` from `RLMRealm` instances in other threads will block | ||
until the current write transaction completes. | ||
Only one write transaction can be open at a time for each Realm file. Write |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Drop the "file": "for each Realm.". This will make the doc more generalized because we don't really expose that in-memory or synced Realms are backed by files.
@@ -202,6 +224,40 @@ typedef void (^RLMNotificationBlock)(RLMNotification notification, RLMRealm *rea | |||
- (BOOL)commitWriteTransaction:(NSError **)error; | |||
|
|||
/** | |||
Commits all write operations in the current write transaction, without | |||
notifying specific callbacks of the changes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"callbacks" -> "notification blocks"
|
||
Notifications are sent when a write transaction is committed whether or not | ||
automatic refreshing is enabled. | ||
Write transaction will still always advance a Realm to the latest version and |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Write transaction" -> "Write transactions"
@@ -70,6 +70,13 @@ - (void)stop { | |||
_block = nil; | |||
} | |||
|
|||
- (void)suppressNextNotification { | |||
auto block = _block; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A brief comment or different variable name might help explain what this is doing.
It wasn't immediately clear to me that this approach to suppressing notifications completely bypasses the Object Store's mechanism for suppressing notifications.
[realm deleteAllObjects]; | ||
[realm commitWriteTransactionWithoutNotifying:@[token] error:nil]; | ||
|
||
// local realm notifications are called synchronously so no need to wait for anything |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[token stop]
to prevent the deallocation warning from being logged?
RLMRealm *realm = [RLMRealm defaultRealm]; | ||
[realm beginWriteTransaction]; | ||
XCTAssertThrows([realm commitWriteTransactionWithoutNotifying:@[token] error:nil]); | ||
[realm cancelWriteTransaction]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[token stop]
to prevent the deallocation warning from being logged?
[realm beginWriteTransaction]; | ||
XCTAssertThrows([otherRealm commitWriteTransactionWithoutNotifying:@[_token] error:nil]); | ||
[realm cancelWriteTransaction]; | ||
[otherRealm cancelWriteTransaction]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[token stop]
to prevent the deallocation warning from being logged?
Write transactions cannot be nested, and trying to execute a write transaction on a Realm which is already | ||
participating in a write transaction will throw an error. Calls to `write` from `Realm` instances in other threads | ||
will block until the current write transaction completes. | ||
Only one write transaction can be open at a time for each Realm file. Write |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"for each Realm."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just plain "for each Realm" is misleading, as to me it sounds like it's referring to Realm
instances.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, ok. Hard to come up with phrasing that is generalized, accurate and not misleading. Fine to keep as-is.
Collection notifications aren't sent recursively (because it can't be done in any consistent and useful way), so do the same for Realm notifications for consistency.
668b417
to
a6f36c9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉 🎉 🎉
Is there a way to use closures for this? i.e.: try realm.write(withoutNotifying: tokens) {
store.accounts.move(from: source, to: destination)
} Right now, I'm using: realm.beginWrite()
store.accounts.move(from: source, to: destination)
try realm.commitWrite(withoutNotifying: tokens) |
No, there's no closure version of this API yet. We've considered that exact API that you've proposed in your comment, and might end up adding that in the future. |
Obj-c/Swift side of realm/realm-object-store#200. This is mostly just tests and doc updates since everything interesting is done in the object store.
Closes #3665.