sten
sten

Reputation: 7476

update property in all edges, fast?

I want to update a property in every "edge" every n-cycles/seconds/minutes. As you may suspect this is time consuming and probably wont work well.

One possible approach is to do it in chunks. The question is what is the best way to do it.

Here is how a full sweep will look like :

 match (n1)-[x:q]-(n2)
 set x.decay = x.decay * exp(-rate)

So the idea is to decay the edges and remove them when they hit a specific value.

If I do it in chunks how do I keep track which ones I decayed already so that I skip them, faster and cheaper.

Upvotes: 0

Views: 83

Answers (1)

cybersam
cybersam

Reputation: 67009

Sounds like you need a better approach.

For example, store the calculated expiration time (as a timestamp) in every relationship. And a query that wants to use such a relationship could test that it had not expired. This way, there is no need to update any relationship properties, and all queries will get the correct behavior (down to the millisecond).

Here is a sample snippet:

...
MATCH (foo)-[rel:REL]->(bar)
WHERE timestamp() < rel.expiration

You can also periodically remove expired relationships to clean up the DB and improve query performance.

Upvotes: 1

Related Questions