neodash icon indicating copy to clipboard operation
neodash copied to clipboard

Fix idea: concurrency control using last-read-wins global variable (suggestions welcome)

Open hlin-neo4j opened this issue 1 year ago • 1 comments

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.

hlin-neo4j avatar Nov 27 '24 16:11 hlin-neo4j