Holochain Forum

What is best-practice for rollups, like running a count of nodes (AND upvotes) on a branch?

The design of the hApp so far is a tree structure of nodes. Each node has an “upvote” or “counterpoint” option. Clicking on “counterpoint” adds a new node (but clicking on “upvote” does not add a new node).

Each node has an integer, positive or negative, representing the relative number of upvotes/counterpoints. An upvote counts as +1 on the node, and a counterpoint counts as -1 on the node.

To make things tricky, each upvote on a counterpoint (e.g., new node) counts as -1 on the parent as well.

Here is a quick video from a visualizer I’m writing in Javascript to design the hApp prior to implementing it in the SDK.

Cascading relative weight?

My question is, given the agent-centric design and eventually-consistent data, what would be the best way to keep the integers on every node up to date? My initial thought is that the user who adds an upvote or counterpoint should run a function that descends the chain of nodes in its branch, updating the numbers of each node as the function descends the chain. However, I’m having trouble conceptualizing what would happen if two users were to do this nearly simultaneously. Because the count of user A wouldn’t be done by the time user B starts their count, both would be updating the node numbers on the same set of old data, not taking each other’s additions or subtractions into account. How might one go about mitigating this problem?

I was looking at this, but I’m not sure I completely understand. Does callSync pause any and all processing of the zome in the hApp across each user’s conductor until the promise returns?

I feel like this is one of those circumstances where “data-centric” thinking might be holding me back, but if so, please bust me out of it! :slight_smile:

Thank you!!!
Matt Habermehl