Gremlin - avoid traversing already seen edges

Viewed 29

I've the following model which I'd like to model as a graph in Azure CosmmodDB. enter image description here

So I have a user that can be in multiple groups, user can also have multiple permissions attached, groups can also have multiple permissions attached. I want to find an efficient query that starting from User, I get all the permissions attached (either directly attached or via a group). One thing to add is that user and group may be assigned to the same permission (and I want to get it just once). I came up with the query:

 g.V().hasLabel('user').has('userid', '0_2147483647').repeat(out().simplePath()).until(hasLabel('permission'))

This query is not very efficient when there is much data, so the question is: can we make it better ?

1 Answers

I don't see a reason to use repeat() here as the depth of your traversal is known. I would just do:

g.V().has('user`, 'userid', '0_2147483647').
  union(out('has'),
        out('isingroup').out('has')).
  dedup()
Related