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

Async property query returns result too early #70

Closed
Buggaboo opened this issue Nov 5, 2019 · 2 comments
Closed

Async property query returns result too early #70

Buggaboo opened this issue Nov 5, 2019 · 2 comments

Comments

@Buggaboo
Copy link
Contributor

Buggaboo commented Nov 5, 2019

If you run the branch #51 and #58, and compare the count and find result on the PropertyQuery, you'll find that the find function sometimes returns a partially correct result set, with certain random bytes (every time you run it), that are the same as the random bytes as count consistently returns.

This leads me to think that these obx functions return via ffi before the actual correct values are populated on the array alloc. This reminds me of the async await the Future discussion #49 .

@Buggaboo Buggaboo changed the title OBX_bytes property query returns result too early Async OBX_bytes property query returns result too early Nov 5, 2019
@Buggaboo Buggaboo changed the title Async OBX_bytes property query returns result too early Async property query returns result too early Nov 5, 2019
@Buggaboo
Copy link
Contributor Author

Buggaboo commented Nov 14, 2019

In the meantime, the users should sum, avg, etc. on Entity properties, using, higher-order dart functions on collections, e.g.:

final all = box.getAll(); // or some query
final sum = all.map((s) => s.someIntProp ?? 0).toList().reduce((a,b) => a + b); // ?? if prop is nullable
final avg  = sum / box.count();
final maxEntityOfSomeProp = all.reduce((a, b) => a.someIntProp > b.someIntProp ? a : b);
final maxOfProp = maxEntityOfSomeProp[0].someIntProp;

@vaind vaind mentioned this issue Nov 18, 2019
@vaind
Copy link
Collaborator

vaind commented Nov 18, 2019

There is no async property query. The native call is synchronous, it cannot return before the data is ready.

I've found the issue causing wrong results of find() - it's a regression in OBX_id_array::items() introduced during the conversion to dart2.6. It stopped returning a copy of the list, as the comment said and returned a reference to the original list. You've used this method as a template when implementing the other obx_*_array structs, thus replicating this problem.
See 7641c85 for a fix.

Closing this issue, let's address the rest (if there are any more problems) in a property-query PR.

BTW regarding all the OBX_*_array structs - could a generic be used instead of having a copy of each? That should also reduce the amount of duplication in the caller code

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

No branches or pull requests

2 participants