neodash
neodash copied to clipboard
Fix idea: concurrency control using last-read-wins global variable (suggestions welcome)
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.
Quality Gate passed
Issues
3 New issues
0 Accepted issues
Measures
0 Security Hotspots
0.0% Coverage on New Code
0.0% Duplication on New Code