Rights performance improvements for lists and namespaces #54

Merged
konrad merged 14 commits from improvement/rights-performance into master 2019-01-21 22:08:05 +00:00
1 changed files with 19 additions and 22 deletions
Showing only changes of commit 43f73c692d - Show all commits

View File

@ -92,30 +92,27 @@ func (l *List) checkListRight(user *User, rights ...ListRight) bool {
var conds []builder.Cond
for _, r := range rights {
// User conditions
conds = append(conds, builder.Or(
// If the list was shared directly with the user and the user has the right
builder.And(
builder.Eq{"ul.user_id": user.ID},
builder.Eq{"ul.right": r},
),
// If the namespace this list belongs to was shared directly with the user and the user has the right
builder.And(
builder.Eq{"un.user_id": user.ID},
builder.Eq{"un.right": r},
),
// If the list was shared directly with the user and the user has the right
conds = append(conds, builder.And(
builder.Eq{"ul.user_id": user.ID},
builder.Eq{"ul.right": r},
))
// If the namespace this list belongs to was shared directly with the user and the user has the right
conds = append(conds, builder.And(
builder.Eq{"un.user_id": user.ID},
builder.Eq{"un.right": r},
))
// Team rights
conds = append(conds, builder.Or(
// If the list was shared directly with the team and the team has the right
builder.And(
builder.Eq{"tm2.user_id": user.ID},
builder.Eq{"tl.right": r},
),
// If the namespace this list belongs to was shared directly with the team and the team has the right
builder.And(
builder.Eq{"tm.user_id": user.ID},
builder.Eq{"tn.right": r},
),
// If the list was shared directly with the team and the team has the right
conds = append(conds, builder.And(
builder.Eq{"tm2.user_id": user.ID},
builder.Eq{"tl.right": r},
))
// If the namespace this list belongs to was shared directly with the team and the team has the right
conds = append(conds, builder.And(
builder.Eq{"tm.user_id": user.ID},
builder.Eq{"tn.right": r},
))
}