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

in function can #19824

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

in function can #19824

wants to merge 2 commits into from

Conversation

egmsystems
Copy link

/* @var string $json to cache the $params too */
$allowCaching && $json = json_encode($params);
if ($allowCaching && isset($this->_access[$permissionName][$json])) {
return $this->_access[$permissionName][$json];
}
...
if ($allowCaching) {
$this->_access[$permissionName][$json] = $access;
}

Q A
Is bugfix? ✔️/❌
New feature? ✔️/❌
Breaks BC? ✔️/❌
Fixed issues

/* @var string $json to cache the $params too */
$allowCaching && $json = json_encode($params);
if ($allowCaching && isset($this->_access[$permissionName][$json])) {
        return $this->_access[$permissionName][$json];
}
 ...
if ($allowCaching) {
        $this->_access[$permissionName][$json] = $access;
}
@what-the-diff
Copy link

what-the-diff bot commented May 4, 2023

PR Summary

  • Improved user access caching
    The cache for user's access is now stored more efficiently using a multidimensional array.
  • Cache storage with parameters
    When caching is enabled, parameters are stored as JSON format along with the cache to enhance retrieval.
  • Cached results checking before AccessChecker
    Prior to checking with AccessChecker, the system examines available cached results for the given permission and parameters.
  • Saving parameters with cache data
    To speed up future checks, parameters are saved with the cache, allowing faster retrieval from memory/cache instead of needing to go through AccessChecker repeatedly.

@bizley
Copy link
Member

bizley commented May 4, 2023

Hm, why were parameters not cached in the first place? 🤔 Anyway, md5 might be a better solution because of the json locale converting, encoding problems, etc.

@egmsystems
Copy link
Author

Hm, why were parameters not cached in the first place? 🤔 Anyway, md5 might be a better solution because of the json locale converting, encoding problems, etc.

i thinked it but when i am debuging i would like see the parameters values. Other way is use print_r.

parameters not cached in the first place may be this var chache use ram and it can have memory limitation; then it will can use app cache

@bizley bizley requested a review from a team May 12, 2023 12:34
Copy link
Contributor

@schmunk42 schmunk42 left a comment

Choose a reason for hiding this comment

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

I am against this change in the current form.

If you have some kind of check with can with different params for every call this will blow up your cache.

@egmsystems
Copy link
Author

I am against this change in the current form.

If you have some kind of check with can with different params for every call this will blow up your cache.

then it can with send parameter false to $allowCaching
can($permissionName, $params = [], $allowCaching = true)

@schmunk42
Copy link
Contributor

then it can with send parameter false to $allowCaching can($permissionName, $params = [], $allowCaching = true)

but you need to update existing code, it would be OK if you could enable that with a global option like enableCachingWithParams to turn this on.

@bizley @samdark Actually we're in code-freeze state ... related discussion: #19831

@rob006
Copy link
Contributor

rob006 commented May 13, 2023

If you have some kind of check with can with different params for every call this will blow up your cache.

Memory usage is not that bad if we use md5() to hash JSON - then it is less than 2MB for every 10k variations. I would be more concerned about lack of cache here than this kind of memory usage.

The bigger problem is that we don't know what is passed as $params - it could be object that cannot be converted to JSON, or even serialized.

@bizley
Copy link
Member

bizley commented May 14, 2023

We could rely on the developer with $allowCaching 🙄 ... (yeah, right) or add check for any errors in json_encode...

@schmunk42
Copy link
Contributor

If you have some kind of check with can with different params for every call this will blow up your cache.

Memory usage is not that bad if we use md5() to hash JSON - then it is less than 2MB for every 10k variations. I would be more concerned about lack of cache here than this kind of memory usage.

My concern was, if someone has ie. {'timestamp': 1684138273459} (current time with ms) as params, it will create a huge amount of useless entries in no time.

@rob006
Copy link
Contributor

rob006 commented May 15, 2023

My concern was, if someone has ie. {'timestamp': 1684138273459} (current time with ms) as params, it will create a huge amount of useless entries in no time.

I would not expect that someone will call this method 100k times in a single request.

@schmunk42
Copy link
Contributor

I would not expect that someone will call this method 100k times in a single request.

Ah sorry, I thought it would be written into the app cache.

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.

None yet

4 participants