1

For a given user I want to get all the runs that

  • satisfy some conditions
  • get only runs from projects that the user has access to

In Users table, every user has a list of project ids while in Runs table, every run has a project id. The following is a query that works. Can it be optimized using concatMap?

r.table('users')
.inner_join(
    r.table('runs').filter( lambda var_6: (<some_condns>), 
         lambda user, run: user['projects'].contains(run['project_id'])
    )
.filter(lambda l: l['left']['id'] == '<user_id>').without('left')

I think equiJoin may not work because I am looking for item in a list as apposed to equality.

Sant
  • 31
  • 4

1 Answers1

0

The below worked perfectly well for me -

 r.table("users").get_all(user_id).map(lambda user:
     {
        "run_array": r.table("runs").filter(lambda var_6: (<some_condns>))
               .filter(lambda run: 
                  user['projects'].contains(run["project_id"]))
                    .coerce_to("array")
     }).concat_map(lambda run: run['run_array'])
Sant
  • 31
  • 4