Skip to content
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

Merged
merged 8 commits into from Nov 18, 2016

Conversation

tgoyne
Copy link
Member

@tgoyne tgoyne commented Oct 24, 2016

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.

@tgoyne tgoyne self-assigned this Oct 24, 2016
// notification is called (the first would error on .update)
theExpectation = expectation(description: "")
let realm = realmWithTestPath()
realm.beginWrite();
Copy link
Contributor

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

@jpsim
Copy link
Contributor

jpsim commented Nov 15, 2016

Are any of the failing CI jobs relevant?

@tgoyne
Copy link
Member Author

tgoyne commented Nov 15, 2016

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrong changelog section

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@tgoyne
Copy link
Member Author

tgoyne commented Nov 17, 2016

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).

@jpsim
Copy link
Contributor

jpsim commented Nov 17, 2016

SwiftLint errors are for files not modified in this PR

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
Copy link
Contributor

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.

@tgoyne
Copy link
Member Author

tgoyne commented Nov 17, 2016

The Travis Swiftlint check failed. I assume it's running a different version of swiftlint.

@jpsim
Copy link
Contributor

jpsim commented Nov 17, 2016

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.

@tgoyne tgoyne force-pushed the tg/changeset-skip branch 2 times, most recently from d874972 to 33d19aa Compare November 17, 2016 23:03
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
Copy link
Contributor

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.
Copy link
Contributor

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
Copy link
Contributor

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;
Copy link
Contributor

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
Copy link
Contributor

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];
Copy link
Contributor

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];
Copy link
Contributor

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"for each Realm."

Copy link
Member Author

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.

Copy link
Contributor

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.
Copy link
Contributor

@jpsim jpsim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉 🎉 🎉

@chrisamanse
Copy link

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)

@jpsim
Copy link
Contributor

jpsim commented Nov 28, 2016

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add write transactions which do not produce local notifications
3 participants