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

fix: separate post-commit invalidation callbacks from trigger and user callbacks #144

Merged
merged 2 commits into from
Dec 23, 2021

Conversation

wschurman
Copy link
Member

Why

The issue we're seeing is:

  • A post-commit trigger is calling load on data that was deleted. This call should be possible (using loadNullable).
  • The cache still has data in it since the ordering of post-commit callbacks is undefined.
  • The data is loaded even though it no longer exists.

How

To fix this, add some strict ordering to post-commit callbacks to ensure that post-commit invalidations run before any other callbacks. This ensures that the post-commit callbacks that access the cache have consistent cache loads.

Test Plan

  • Run the new test without the fix, see that it fails (the exception is thrown)
  • Run the new test with the fix, see that it passes.

@wschurman wschurman requested review from jkhales and ide December 22, 2021 19:25
@codecov
Copy link

codecov bot commented Dec 22, 2021

Codecov Report

Merging #144 (ba45e80) into master (c4df889) will increase coverage by 0.01%.
The diff coverage is 100.00%.

❗ Current head ba45e80 differs from pull request most recent head fcf5dc2. Consider uploading reports for the commit fcf5dc2 to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##           master     #144      +/-   ##
==========================================
+ Coverage   95.89%   95.90%   +0.01%     
==========================================
  Files          73       73              
  Lines        1851     1857       +6     
  Branches      228      205      -23     
==========================================
+ Hits         1775     1781       +6     
  Misses         75       75              
  Partials        1        1              
Flag Coverage Δ
integration 95.90% <100.00%> (+0.01%) ⬆️
unittest 95.90% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
packages/entity/src/EntityMutator.ts 98.20% <100.00%> (ø)
packages/entity/src/EntityQueryContext.ts 100.00% <100.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 c4df889...fcf5dc2. Read the comment docs.

Copy link
Member

@ide ide left a comment

Choose a reason for hiding this comment

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

Sounds right. Triggers logically don't care about the cache. There still is a race condition where another process reading the same data at this time could fill the cache, but we have that problem anyway.

…stency-test.ts

Co-authored-by: James Ide <ide@users.noreply.github.com>
@wschurman wschurman merged commit efa131e into master Dec 23, 2021
@wschurman wschurman deleted the @wschurman/separate-invalidation-callbacks branch December 23, 2021 20:41
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

Successfully merging this pull request may close these issues.

2 participants