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

User/Role/Feature lookup improvements #888

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

NickLaMuro
Copy link
Member

Requires ManageIQ/manageiq#20506

Makes use of new scopes to improve the number of queries required for login and even regular requests (though, the latter is less significant).

Also avoids some duplicate User lookups on login.

Benchmarks

Note: Improvements are in number of queries.

Before

$ bundle exec miqperf benchmark -ac2 "/api/users"
$ bundle exec miqperf report --last
/api/auth
|   ms | queries | query (ms) | rows |
| ---: |    ---: |       ---: | ---: |
| 5088 |      26 |        183 |   10 |
/api/users
|   ms | queries | query (ms) | rows |
| ---: |    ---: |       ---: | ---: |
|  267 |      12 |         13 | 1494 |
|   17 |      10 |        3.9 |   12 |

After

$ bundle exec miqperf benchmark -ac2 "/api/users"
$ bundle exec miqperf report --last
/api/auth
|   ms | queries | query (ms) | rows |
| ---: |    ---: |       ---: | ---: |
| 4949 |      12 |        181 |    1 |
/api/users
|   ms | queries | query (ms) | rows |
| ---: |    ---: |       ---: | ---: |
|  258 |       7 |         12 | 1489 |
|   15 |       5 |        3.3 |    7 |

Links

Copy link
Member

@kbrock kbrock left a comment

Choose a reason for hiding this comment

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

this is simple and really nice

one question on the if else, but just a nit

We've made changes exactly like this in the past, so they follow a common pattern.
But I am surprised how much of an impact it made.
very nice find

app/controllers/api/base_controller/authentication.rb Outdated Show resolved Hide resolved
lib/services/api/user_token_service.rb Show resolved Hide resolved
@NickLaMuro
Copy link
Member Author

NickLaMuro commented Sep 2, 2020

Looks like I have a lot of broken tests to fix... I will look into that today.

Edit: Actually, this needs a cross repo test for this to function, so will work on that at some point.

validate_userid(userid)
def generate_token(user_or_id, requester_type, token_ttl: nil)
if user_or_id.kind_of?(User)
userid = user_or_id.userid.downcase
Copy link
Member

Choose a reason for hiding this comment

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

do we still need to do the validation? (at least the "in my region" aspect of what the validate method does)?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think I may have screwed up the if here, and the end should be a line earlier... let me look into this...

(sorry I took so long to respond to this...)

Use the new `:lookup_scope` argument for `.authenticate` and
`.lookup_by_identity` to reduce the number of user based queries on
every request.
While `virtual_delegates` can be used to improve performance via a
single attribute in a query, we already bring back the `miq_user_role`
(via the lookup_scope), so it is better to just use that.

And currently virtual_delegates don't support already loaded
relationships.
There are a few places in the API where we re-fetch the User when it is
already available.

These fixes allow for making use of the existing user that already
exists instead of calling another lookup.  The two places involved are:

- When authenticating using .basic_authentication
- When generating a token for the user (on login)
@miq-bot
Copy link
Member

miq-bot commented Feb 27, 2023

This pull request has been automatically marked as stale because it has not been updated for at least 3 months.

If these changes are still valid, please remove the stale label, make any changes requested by reviewers (if any), and ensure that this issue is being looked at by the assigned/reviewer(s)

Thank you for all your contributions! More information about the ManageIQ triage process can be found in the triage process documentation.

@miq-bot
Copy link
Member

miq-bot commented May 29, 2023

This pull request has been automatically closed because it has not been updated for at least 3 months.

Feel free to reopen this pull request if these changes are still valid.

Thank you for all your contributions! More information about the ManageIQ triage process can be found in the triage process documentation.

@miq-bot miq-bot closed this May 29, 2023
@Fryguy Fryguy removed the stale label Jul 27, 2023
@Fryguy Fryguy reopened this Jul 27, 2023
@Fryguy
Copy link
Member

Fryguy commented Jul 27, 2023

cc @kbrock

@miq-bot
Copy link
Member

miq-bot commented Jul 27, 2023

Checked commits NickLaMuro/manageiq-api@d1c9e09~...db287af with ruby 2.6.10, rubocop 1.28.2, haml-lint 0.35.0, and yamllint
4 files checked, 1 offense detected

app/controllers/api/base_controller/authentication.rb

@miq-bot miq-bot added the stale label Oct 30, 2023
@miq-bot
Copy link
Member

miq-bot commented Oct 30, 2023

This pull request has been automatically marked as stale because it has not been updated for at least 3 months.

If these changes are still valid, please remove the stale label, make any changes requested by reviewers (if any), and ensure that this issue is being looked at by the assigned/reviewer(s)

Thank you for all your contributions! More information about the ManageIQ triage process can be found in the triage process documentation.

@kbrock kbrock removed the stale label Oct 30, 2023
@miq-bot
Copy link
Member

miq-bot commented Feb 5, 2024

This pull request has been automatically marked as stale because it has not been updated for at least 3 months.

If these changes are still valid, please remove the stale label, make any changes requested by reviewers (if any), and ensure that this issue is being looked at by the assigned/reviewer(s).

@miq-bot miq-bot added the stale label Feb 5, 2024
@miq-bot
Copy link
Member

miq-bot commented May 6, 2024

This pull request has been automatically marked as stale because it has not been updated for at least 3 months.

If these changes are still valid, please remove the stale label, make any changes requested by reviewers (if any), and ensure that this issue is being looked at by the assigned/reviewer(s).

1 similar comment
@miq-bot
Copy link
Member

miq-bot commented Aug 12, 2024

This pull request has been automatically marked as stale because it has not been updated for at least 3 months.

If these changes are still valid, please remove the stale label, make any changes requested by reviewers (if any), and ensure that this issue is being looked at by the assigned/reviewer(s).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants