Skip to content

Commit b406381

Browse files
committed
Move current roles to a global
I believe globals are calculated once per query now in v5, so I'm hoping this helps improve performance.
1 parent 04feb02 commit b406381

File tree

2 files changed

+5
-10
lines changed

2 files changed

+5
-10
lines changed

dbschema/common.esdl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ module default {
22
global currentActorId: uuid;
33
global currentActor := (select Actor filter .id = global currentActorId);
44
global currentUser := (select User filter .id = global currentActorId);
5-
5+
global currentRoles := (global currentActor).roles;
6+
67
scalar type ReportPeriod extending enum<Monthly, Quarterly>;
78

89
# Helper function to workaround native support for sort ignoring accents

src/components/authorization/policies/conditions/role.condition.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,11 @@ export class RoleCondition implements Condition {
2121
return 'false';
2222
}
2323

24-
setupEdgeQLContext({ namespace }: AsEdgeQLParams<any>) {
25-
const User = fqnRelativeTo('default::User', namespace);
26-
const currentUserId = fqnRelativeTo('default::currentUserId', namespace);
27-
return {
28-
givenRoles: `(<${User}>(global ${currentUserId})).roles`,
29-
};
30-
}
31-
3224
asEdgeQLCondition({ namespace }: AsEdgeQLParams<any>) {
25+
const currentRoles =
26+
'global ' + fqnRelativeTo('default::currentRoles', namespace);
3327
const roleType = fqnRelativeTo('default::Role', namespace);
34-
return eqlDoesIntersect('givenRoles', this.allowed, roleType);
28+
return eqlDoesIntersect(currentRoles, this.allowed, roleType);
3529
}
3630

3731
union(this: void, conditions: this[]) {

0 commit comments

Comments
 (0)