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

[RDART-968] Add support for keypath filtering on object #1601

Merged
merged 25 commits into from Apr 18, 2024

Conversation

papafe
Copy link
Contributor

@papafe papafe commented Mar 22, 2024

This PR adds the changeFor([List<String>? keyPaths] method to the generated realm classes to support keypath filtering on object notifications

TODO

  • Changelog
  • Documentation
  • Fix generator tests
  • Tests
  • Fix backlink tests
  • Fix mapped property tests

* main: (31 commits)
  Add vNext Changelog header (#1594)
  [Release 2.0.0] (#1593)
  Cleanup the changelog for 2.0.0 (#1592)
  Wrong test for local development (#1591)
  Add vNext Changelog header (#1589)
  [Release 2.0.0-beta.2] (#1588)
  Update melos to 5.2.0 (#1587)
  RDART-977: Hierarchical logger (#1574)
  Fix release workflow (#1582)
  RDART-978: Add support RealmValue.fromJson (#1581)
  Fix oversight in install command
  Add vNext Changelog header (#1579)
  [Release 2.0.0-beta.1] (#1577)
  RDART-976: Fix install command (#1576)
  Update build instructions and switching Flutter/Dart versions (#1571)
  gitignore release folder
  Remove incorrectly committed files
  Cleanup changelog, bring back melos publishing (#1573)
  Add vNext Changelog header (#1572)
  [Release 2.0.0-alpha.5] (#1570)
  ...
@papafe
Copy link
Contributor Author

papafe commented Mar 26, 2024

@nirinchev @nielsenko It's still a little rough, but I thought it would be a good idea if you could give me some initial feedback, so I know I'm going in the right direction

});

// TODO Need to decide what we expect here....
test('mappedProperty', () async {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This test at the moment passes, but we should decide what kind of behaviour we want to have with mapped properties.
At the moment we need to pass the "managed" name when we subscribe, but we get the mapped name in changes

return getChangesFor<T>(object, null);
}

//TODO we need to decide if we want to have keyPaths be nullable here of we force developers to use getChanges in that case
Copy link
Contributor Author

Choose a reason for hiding this comment

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

What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

As a user, you will not be using these, but the property changes and the method changesFor, so I don't think it matter that much.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think I put this comment in the wrong place, but I was actually referring to changesFor, that at the moment can accept a null argument. Should we keep it like this? Ot should we make the keypath argument non-nullable and force developers to use changes for the default notifications?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should allow null as well, so changes and changesFor(null) is essentially the same.

@papafe
Copy link
Contributor Author

papafe commented Apr 5, 2024

This is more or less reviewable. I'm still trying to understand why the backlink tests are failing (it seems that no backlink notifications are raised).
Apart from that I left some notes in the PR for things I'm not sure about, and I'll keep the list of TODOs updated in the PR description.
I will do housekeeping (fixing the changelog, generator tests, documentation, ...) once I get a first pass at the PR, in case I'm doing something completely wrong and I need to change my approach 😉

Copy link
Contributor

@nielsenko nielsenko left a comment

Choose a reason for hiding this comment

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

So far so good 👍 . I'll take another look once you set it ready-for-review.

For other reviewers. The double creation of the keypathNative array is a small blemish we already discussed and will address in a later PR

Comment on lines 1798 to 1811
[List<String>? keyPaths, int? classKey]) {
return using((Arena arena) {
Pointer<realm_key_path_array> kpNative = nullptr;

if (keyPaths != null && classKey != null) {
final length = keyPaths.length;
final keypathsNative = arena<Pointer<Char>>(length);

for (int i = 0; i < length; i++) {
keypathsNative[i] = keyPaths[i].toCharPtr(arena);
}

kpNative = _realmLib.invokeGetPointer(() => _realmLib.realm_create_key_path_array(object.realm.handle._pointer, classKey, length, keypathsNative));
}
Copy link
Contributor

Choose a reason for hiding this comment

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

LGTM

Perhaps get the classKey from the realmObject instead of passing it as an argument?

packages/realm_dart/lib/src/native/realm_core.dart Outdated Show resolved Hide resolved
return getChangesFor<T>(object, null);
}

//TODO we need to decide if we want to have keyPaths be nullable here of we force developers to use getChanges in that case
Copy link
Contributor

Choose a reason for hiding this comment

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

As a user, you will not be using these, but the property changes and the method changesFor, so I don't think it matter that much.

packages/realm_dart/lib/src/realm_object.dart Outdated Show resolved Hide resolved
* main:
  RDART-996: Don't serialize backlinks (#1617)
  Update README.md (#1608)
  RDART-983: Refactor how we open dynamic library to give better error message (#1614)
  RDART-991: Rename Key enum (#1613)
  RDART-992: Handle Identifer expression as well (#1612)
  Add workflow_dispatch for development
  Common setup script (#1610)
  RDART-992: Const initializer evaluation is too simple (#1607)

# Conflicts:
#	CHANGELOG.md
@papafe papafe marked this pull request as ready for review April 8, 2024 12:44
@papafe
Copy link
Contributor Author

papafe commented Apr 8, 2024

@nielsenko fixed the comments on the PR, added documentation and changelog entry, fixed the generated code tests
The only thing missing is fixing the backlinks and mapped property tests, for which I'm waiting for some inputs from core

@papafe papafe changed the title [RDART-968] [WIP] Add support for keypath filtering on object [RDART-968] Add support for keypath filtering on object Apr 8, 2024
@papafe papafe requested a review from nielsenko April 11, 2024 14:24
Copy link
Contributor

@nielsenko nielsenko left a comment

Choose a reason for hiding this comment

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

LGTM

* main:
  New documentation URL (#1621)
  RDART-980: Add tests for collections in `Mixed` with synced realms (#1585)
  RDART-987: Schema migration support follow-up (#1622)
  Update changelog for collections in mixed and sync
  RDART-987: Schema migration support (#1586)

# Conflicts:
#	packages/realm_dart/test/realm_value_test.realm.dart
Copy link

Pull Request Test Coverage Report for Build 8703959258

Details

  • 33 of 35 (94.29%) changed or added relevant lines in 3 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.05%) to 86.398%

Changes Missing Coverage Covered Lines Changed/Added Lines %
packages/realm_dart/lib/src/realm_object.dart 13 15 86.67%
Totals Coverage Status
Change from base Build 8659161761: 0.05%
Covered Lines: 5882
Relevant Lines: 6808

💛 - Coveralls

@papafe papafe merged commit 905874c into main Apr 18, 2024
57 checks passed
@papafe papafe deleted the fp/keypath-filtering branch April 18, 2024 08:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants