I would like to know if there is a way to efficiently increment a facet value without having to go through the application layer.
I’m looking at a data model that involves observations and observation points, with a “seen_by” edge going into the observation point node from an observation, which facets on that edge for the observation count on this location, the first seen and the last seen date. The problem here is that I am aiming for a high number of updates, i.e. I have a constant stream of observations to update the graph with, most of which are already existing as nodes. So at the moment I would need to do a separate query per added observation to:
- check whether the observation already exists and get its uid
- check whether the edge to the indicated observation point already exists and get its uid
- obtain the current count facet value if the edge exists
Then I can selectively construct a mutation that creates the non-existing nodes and updates/creates the edge, adding the new count to the existing count on the edge.
Setting first_seen on the edge can be done via an additional conditional mutation if it is not present. Last_seen will always be updated.
I can see that with conditional upsert blocks I might be able to handle the edge and node checking and creation, but one thing I do not see how to address is the counter increment. Is there an efficient way to do this on the database side? I would like to be able to handle thousands of updates per second, and any round-trip I can shave of the execution time would help.