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

Implement simple Streams on DatabaseViews, fix multi-dao changelistener #320

Merged
merged 11 commits into from
May 23, 2020

Conversation

mqus
Copy link
Collaborator

@mqus mqus commented May 1, 2020

Like I explained on the slack, here is a prototype for Queries with the result Stream<X> where X is a @DatabaseView.

As it won't detect the dependencies of each DatabaseView, it simply updates the Streams of all views if any entity was updated. If a library user is frequently changing his entities while having one particularly intensive view (like a join) as a Stream, it will get quite resource-heavy even if the entity and the DatabaseView of the Stream are not related at all. But its better than nothing.

Of course, I think we should strive to make the Streams of DatabaseViews better by making them aware of the entities they depend on but as mentioned previously this can get very complex.

I also fixed a related issue where Streams of Entity E in DAO B were only updated by insert/update/delete methods in DAO C if there was another query of a Stream of E in C because Streams were only tracked separately for each DAO even if the changeListener was database-global.

TODO:

  • remove error message for stream queries on views (it doesn't get thrown anymore but it's still there)
  • implement tests
    • implement Tests (only adapted existing ones so far) for the Streams on Views
    • implement Test for the fix
  • implement integration tests
    • implement Tests for the Streams on Views
    • implement Regression Test for the issue
  • add documentation and mention that it's expensive

I'll finish this up if you agree on the concept, @vitusortner .

@mqus mqus marked this pull request as draft May 1, 2020 16:33
@codecov
Copy link

codecov bot commented May 1, 2020

Codecov Report

Merging #320 into develop will decrease coverage by 0.03%.
The diff coverage is 59.52%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop     #320      +/-   ##
===========================================
- Coverage    81.47%   81.43%   -0.04%     
===========================================
  Files           59       59              
  Lines         1506     1503       -3     
===========================================
- Hits          1227     1224       -3     
  Misses         279      279              
Flag Coverage Δ
#floor 81.43% <59.52%> (-0.04%) ⬇️
#floor_generator 81.09% <57.50%> (-0.05%) ⬇️
Impacted Files Coverage Δ
.../processor/error/query_method_processor_error.dart 100.00% <ø> (ø)
floor_generator/lib/value_object/dao.dart 4.00% <0.00%> (-0.35%) ⬇️
floor_generator/lib/value_object/database.dart 12.00% <22.22%> (+6.73%) ⬆️
floor/lib/src/adapter/query_adapter.dart 92.68% <100.00%> (ø)
floor_generator/lib/processor/dao_processor.dart 100.00% <100.00%> (ø)
...enerator/lib/processor/query_method_processor.dart 100.00% <100.00%> (ø)
floor_generator/lib/writer/dao_writer.dart 100.00% <100.00%> (ø)
...loor_generator/lib/writer/query_method_writer.dart 100.00% <100.00%> (ø)
floor_generator/lib/value_object/view.dart 90.00% <0.00%> (+30.00%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 49fbff2...681d059. Read the comment docs.

@mqus mqus added the feature Request and implementation of a feature (release drafter) label May 1, 2020
@mqus mqus mentioned this pull request May 2, 2020
9 tasks
Copy link
Collaborator

@vitusortner vitusortner left a comment

Choose a reason for hiding this comment

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

Thanks for these changes! Until we have proper query parsing in place, this seems to be a good solution!

Can you please mark the area for the fix? I had trouble finding it 🙏

floor_generator/lib/processor/dao_processor.dart Outdated Show resolved Hide resolved
floor_generator/lib/value_object/dao.dart Show resolved Hide resolved
floor_generator/lib/writer/query_method_writer.dart Outdated Show resolved Hide resolved
floor_generator/lib/writer/query_method_writer.dart Outdated Show resolved Hide resolved
@mqus mqus force-pushed the expensive-view-streams branch from 7fd841c to d2539a0 Compare May 20, 2020 14:35
@cassioseffrin
Copy link
Contributor

Do you have an estimative when streams on views will be released?

@mqus
Copy link
Collaborator Author

mqus commented May 20, 2020

Not exactly but maybe soon. There are just some tests left to do which I will try to tackle tomorrow. vitusortner will review again afterwards, although there shouldn't be major issues left, so this would then be ready to be merged. I don't know if there are plans for a new release.

But as mentioned, this is just a (possibly runtime-intensive)stopgap solution until I'm finished with integrating the sqlparser, which will do query-analysis to be more efficient when updating the Stream.
But I really can't give an ETA for that and help is appreciated.
EDIT: I added a Roadmap for the finished Queryparser to the tracking issue: #321

@cassioseffrin
Copy link
Contributor

Query-analysis will be awesome! I am waiting for it!

@mqus
Copy link
Collaborator Author

mqus commented May 21, 2020

@vitusortner I noticed that we actually don't test streams quite the right way. Floor's Streams will re-execute the query as soon someone will start to Listen (which is right this way), but that also means that each

expect(actual, emits([anything]));

in the tests just starts listening and reexecutes the query, not actually looking if an event was fired independently. Previously fired events will be discarded if no-one is actually listening. This means that our Stream tests are just checking if the insert/update/delete query got executed, not if the stream fired.

For the new tests added here I'm using

expect(actual, emitsInOrder([firstResult,secondResult]));

at the start of the test, which will keep the stream open and actually checks the stream output.

When doing this I noticed that some queries will be executed together before the re-execution of the Stream Query fires, meaning that some events get "lost" and other events will then get a double update.

For that I introduced a new helper function that will introduce artificial wait times to let floor reexecute the SELECT query before the test starts the next database action. I'll push that soon.

@mqus mqus changed the title WIP: Implement simple Streams on DatabaseViews, fix multi-dao changelistener Implement simple Streams on DatabaseViews, fix multi-dao changelistener May 21, 2020
@mqus mqus marked this pull request as ready for review May 21, 2020 12:26
@mqus mqus requested a review from vitusortner May 21, 2020 21:24
@mqus mqus force-pushed the expensive-view-streams branch from e1d8d7c to b0b237f Compare May 22, 2020 18:06
@mqus
Copy link
Collaborator Author

mqus commented May 22, 2020

The last commit is not really necessary... you decide if you want it :)

README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
floor/README.md Outdated Show resolved Hide resolved
floor/README.md Outdated Show resolved Hide resolved
floor/test/integration/dao/person_dao.dart Outdated Show resolved Hide resolved
floor_generator/lib/writer/query_method_writer.dart Outdated Show resolved Hide resolved
floor/test/integration/view/view_test.dart Outdated Show resolved Hide resolved
floor/test/test_util/separate_queries.dart Outdated Show resolved Hide resolved
floor/test/integration/stream_query_test.dart Outdated Show resolved Hide resolved
@vitusortner
Copy link
Collaborator

@vitusortner I noticed that we actually don't test streams quite the right way. Floor's Streams will re-execute the query as soon someone will start to Listen (which is right this way), but that also means that each

expect(actual, emits([anything]));

in the tests just starts listening and reexecutes the query, not actually looking if an event was fired independently. Previously fired events will be discarded if no-one is actually listening. This means that our Stream tests are just checking if the insert/update/delete query got executed, not if the stream fired.

For the new tests added here I'm using

expect(actual, emitsInOrder([firstResult,secondResult]));

at the start of the test, which will keep the stream open and actually checks the stream output.

When doing this I noticed that some queries will be executed together before the re-execution of the Stream Query fires, meaning that some events get "lost" and other events will then get a double update.

For that I introduced a new helper function that will introduce artificial wait times to let floor reexecute the SELECT query before the test starts the next database action. I'll push that soon.

Good find! Thanks

Copy link
Collaborator

@vitusortner vitusortner left a comment

Choose a reason for hiding this comment

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

Looking good 🥇 I'm excited to see this getting merged into the main branch. I'll also create a new release containing these changes in the next days.

As Codecov is blocking this PR from getting merged, I suggest that I'll merge it if you give your go?

@mqus
Copy link
Collaborator Author

mqus commented May 23, 2020

As Codecov is blocking this PR from getting merged, I suggest that I'll merge it if you give your go?

yes please :)

@vitusortner vitusortner merged commit 527b0cb into develop May 23, 2020
@vitusortner vitusortner deleted the expensive-view-streams branch May 23, 2020 20:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Request and implementation of a feature (release drafter)
Development

Successfully merging this pull request may close these issues.

3 participants