Skip to content
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

Merged
merged 1 commit into from
Mar 20, 2017
Merged

Reduce cost of admin user check #8155

merged 1 commit into from
Mar 20, 2017

Conversation

e-dard
Copy link
Contributor

@e-dard e-dard commented Mar 17, 2017

Required for all non-trivial PRs
  • Rebased/mergable
  • Tests pass
  • CHANGELOG.md updated

This PR simplifies the process of checking for the existence of an admin user when handling a query.

joelegasse
joelegasse previously approved these changes Mar 17, 2017
dgnorton
dgnorton previously approved these changes Mar 17, 2017
mark-rushakoff
mark-rushakoff previously approved these changes Mar 17, 2017
@mark-rushakoff mark-rushakoff dismissed their stale review March 17, 2017 19:10

New approach incoming

@e-dard e-dard dismissed stale reviews from joelegasse and dgnorton March 17, 2017 19:30

re-review

@e-dard
Copy link
Contributor Author

e-dard commented Mar 17, 2017

@joelegasse @dgnorton @mark-rushakoff please review 9d9b3254

@@ -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()
Copy link
Contributor

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.

Copy link
Contributor Author

@e-dard e-dard Mar 17, 2017

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.

Copy link
Contributor

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

@@ -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?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should prevent this.

Copy link
Contributor Author

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?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

true

Copy link
Contributor

@mark-rushakoff mark-rushakoff left a 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

@@ -731,6 +751,17 @@ func (data *Data) UnmarshalBinary(buf []byte) error {
return nil
}

// hasUserExists exhaustively checks for the presence of at least one admin
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/hasUserExists/hasAdminUser

@e-dard e-dard force-pushed the er-user-perf branch 2 times, most recently from ba14401 to aeced4f Compare March 17, 2017 19:54
@e-dard e-dard force-pushed the er-user-perf branch 2 times, most recently from 3a57b7d to c7214b8 Compare March 20, 2017 11:48
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.
Copy link
Contributor

@corylanou corylanou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

@e-dard e-dard merged commit 71de233 into master Mar 20, 2017
@e-dard e-dard deleted the er-user-perf branch March 20, 2017 12:50
@e-dard e-dard mentioned this pull request Apr 3, 2017
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants