Fix idea: concurrency control using last-read-wins global variable (suggestions welcome) #1006
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.
For example, the issue is, I have a dashboard with a parameter select card and a Single Value card. I choose parameter X, the single value card should update, but the query takes a while to run, so it shows it's loading. While the query is running, I choose another parameter, triggering the query to run again, but it returns before the first, and updates the single value card. When the first query finally finishes, the single value card gets updated again, incorrectly, with a now-stale value.
Ideally, any transaction about to run against Neo4j should cancel any currently running transactions that shares the same query, but this wasn't trivial and/or not possible to do at the time. Currently, afaik with the source code, all transactions in reports are allowed to run. And so, I dealt with this at the frontend layer. Specifically, I created a global redux variable
lastPopulateQueryTimestamp
associated with the Card state that tracks/represents the latest call of the query. This is set whenever a query is run. When the transaction returns, the logic checks if its timestamp is the same as the global, and only if so, sets the records. In order to get access to that current store inside a non-react component, I had to implement a GET thunk to read and return it. I wrapped it in a dispatch and passed it down the functions so the post-await
block is able to access the store.