ui: Stop ember-data overwriting SyncTimes #12315
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The majority of this PR is just
prettier
(sorry!), the important line is line 218.https://github.com/hashicorp/consul/compare/ui/scratch/more-ember-data-fun#diff-e4c456fea821208520a230bc235b8e5c6692e338129127b7feabe472ed481b6fR218
Background:
ember-data
which additionally caches its own version of truth on the frontend, which is separate from the backend's source of truth (something I've never been onboard with). Therefore the source of truth is no longer 'single'.Therefore:
SyncTime
property to every record in the list which is a timestamp of when the record was received.SyncTime
of every record in ember-data's version of truth. If aSyncTime
is out of date, that therefore means that we didn't receive that record in the last response i.e. it doesn't exist in the actual version of truth on the backend. This means we can delete the record from ember-data's version of truth.SyncTime
based invalidation technique is far more performant than doing 'n something or other' checks/looping to see if anything doesn't exist anymore.The bug:
SyncTime
) are not changed and are overwritten again into the cache whenever a save response is received. i.e. if anything is changed between the time of the request and the time of the response, that change is clobbered.Notes:
The fix:
SyncTime
from the model entirely when we save anything. As we only use this when a blocking query is receivedSyncTime
will be added again following a blocking queries response, and as its deleted locally before ember-data reapplies the saved record to the cache, it won't overwrite a correct, recently updated value.The bigger fix here is obviously not to use ember-data at all - something we are working towards.
Thanks @lkysow for the find! 🙇