-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reduce cost of admin user check #8155
Conversation
@joelegasse @dgnorton @mark-rushakoff please review 9d9b3254 |
services/meta/data.go
Outdated
@@ -576,9 +585,12 @@ func (data *Data) DropUser(name string) error { | |||
for i := range data.Users { | |||
if data.Users[i].Name == name { | |||
data.Users = append(data.Users[:i], data.Users[i+1:]...) | |||
// Maybe we dropped the only admin user? | |||
data.adminUserExists = data.hasAdminUser() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could add a check here to see if the user being removed is an admin, first.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@joelegasse but there could still be another admin lurking in the background.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant if the user isn't an admin, there's not a point in refreshing the cached value
services/meta/data.go
Outdated
@@ -576,9 +585,12 @@ func (data *Data) DropUser(name string) error { | |||
for i := range data.Users { | |||
if data.Users[i].Name == name { | |||
data.Users = append(data.Users[:i], data.Users[i+1:]...) | |||
// Maybe we dropped the only admin user? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should prevent this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't that out of the scope of this PR though?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
true
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One comment typo but code and tests LGTM
services/meta/data.go
Outdated
@@ -731,6 +751,17 @@ func (data *Data) UnmarshalBinary(buf []byte) error { | |||
return nil | |||
} | |||
|
|||
// hasUserExists exhaustively checks for the presence of at least one admin |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/hasUserExists/hasAdminUser
ba14401
to
aeced4f
Compare
3a57b7d
to
c7214b8
Compare
This commits adds a caching mechanism to the Data object, such that when large numbers of users exist in the system, the cost of determining if there is at least one admin user will be low. To ensure that previously marshalled Data objects contain the correct cached admin user value, we exhaustively determine if there is an admin user present whenever we unmarshal a Data object.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good.
Required for all non-trivial PRs
This PR simplifies the process of checking for the existence of an admin user when handling a query.