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

Memoize nil doorkeeper_token #1465

Merged
merged 2 commits into from
Jan 6, 2021
Merged

Conversation

kitop
Copy link
Contributor

@kitop kitop commented Dec 29, 2020

Summary

In some applications extending AccessToken class with custom
functionality, it's some times required to call doorkeeper_token
method directly. If this method is called multiple times, it can cause
repeated DB calls when there's an invalid token that returns nil from
the OAuth::Token.authenticate call.

This could be improved by doing similar as in current_resource_owner,
where it memoizes nil return values for
instance_eval(&Doorkeeper.config.authenticate_resource_owner)

With this proposed change, it will memoize nil doorkeeper_token
values too.

In some applications extending `AccessToken` class with custom
functionality, it's some times required to call `doorkeeper_token`
method directly. If this method is called multiple times, it can cause
repeated DB calls when there's an invalid token that returns `nil` from
the `OAuth::Token.authenticate` call.

This could be improved by doing similar as in `current_resource_owner`,
where it memoizes `nil` return values for
`instance_eval(&Doorkeeper.config.authenticate_resource_owner)`

With this proposed change, it will memoize `nil` doorkeeper_token
values too.
@doorkeeper-bot
Copy link

doorkeeper-bot commented Dec 29, 2020

2 Warnings
⚠️ There're library changes, but not tests. That's OK as long as you're refactoring existing code.
⚠️ Please squash all your commits to a single one

Generated by 🚫 Danger

Copy link
Member

@nbulaj nbulaj left a comment

Choose a reason for hiding this comment

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

LGTM
👍

@nbulaj nbulaj merged commit e06ffed into doorkeeper-gem:master Jan 6, 2021
@nbulaj nbulaj added this to the 5.5 milestone Jan 13, 2021
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.

3 participants