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

Skip context memoization when passing explicit context #267

Conversation

inkstak
Copy link
Contributor

@inkstak inkstak commented May 31, 2024

Fixes #265 - 2nd suggestion :
Skip memoization when an explicit context is passed.

PR checklist:

  • Tests included
  • Documentation updated Not required since it's all about internal memoization
  • Changelog entry added

@inkstak inkstak force-pushed the feature-avoid_memoization_with_explicit_context branch 3 times, most recently from ab8ac45 to 6263ca9 Compare May 31, 2024 09:10
record_key = record._policy_cache_key(use_object_id: true)
context_key = context.values.map { _1._policy_cache_key(use_object_id: true) }.join(".")
context_key = context_for_policy(context).values.map { _1._policy_cache_key(use_object_id: true) }.join(".")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Explicit context was not merged with implicit context to compute cache key.

@inkstak inkstak force-pushed the feature-avoid_memoization_with_explicit_context branch from 6263ca9 to 4f295f6 Compare May 31, 2024 10:14
authorization_context.merge(context).tap do
remove_instance_variable :@_authorization_context
end
end
Copy link
Contributor Author

@inkstak inkstak May 31, 2024

Choose a reason for hiding this comment

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

It seems a bit complicated but it allows to fulfil all the following conditions:

  • Keep memoization by default
  • Skip memoization when passing an explicit context
  • Allow someone to override authorization_context
  • Use any overrided authorization_context as the implicit context to merge with in the explicit one.

(See #217 (comment) & #265 (comment))

@inkstak inkstak marked this pull request as ready for review May 31, 2024 10:23
Copy link

Coverage Status

coverage: 93.801% (+0.1%) from 93.693%
when pulling 4f295f6 on inkstak:feature-avoid_memoization_with_explicit_context
into 2f14a9c on palkan:master.

@palkan palkan closed this in ae2970b Jun 11, 2024
@palkan
Copy link
Owner

palkan commented Jun 11, 2024

Thanks for the PR! I decided to go in a bit different direction (to minimize changes). Now available in master.

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.

Allow to reset authorization context
2 participants