0
votes

I'm studying AWS Neptune with Gremlin to build a permission system. This system would have basically 3 types of vertices: Users, Permissions and Groups.

  • A group has 0..n permissions
  • A user can have 0..n groups
  • A user can be directly connected to 0..n permissions
  • A user can be connected to another user, in which case it "inheritates" that user permission's
  • A group can be inside of another group, that is inside of another group.... so on.

I'm looking for a performant query to find all permissions for a given user.

This graph may get really huge so to stress it out I have build a 17kk user vertices graph, created 10 random edges for each one of them and then created a few permissions.

Then the query I was using to get all permissions is obviouly running forever... n_n'

What I'm trying is simply:

g.V('u01')
    .repeat(out())
    .until(hasLabel('Permission'))
    .simplePath()

Is there a better query to achieve it? Or maybe even a better modeling for this scenario?

I was thinking that maybe my 10 random edges have created a lot of cycles and connections that "make no sense" and thats why the query is slow. Does it make sense?

Thanks in advance!

1

1 Answers

0
votes

You probably running in circles. You should write it like this:

g.V('u01')
    .repeat(out().simplePath())
    .until(hasLabel('Permission'))

It is also preferable the use specific label in the out step to avoid traversing irrelevant paths.