-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
introduce a static fileid->(storage, path) cache #39847
Conversation
Thanks for opening this pull request! The maintainers of this repository would appreciate it if you would create a changelog item based on your changes. |
28e5f1b
to
eee7bc0
Compare
💥 Acceptance tests pipeline cliMain-mariadb10.2-php7.4 failed. The build has been cancelled. |
💥 Acceptance tests pipeline cliProvisioning-mariadb10.2-php7.4 failed. The build has been cancelled. |
I think this has some value. Thanks @butonic I would appreciate your POV @jvillafanez @mrow4a @DeepDiver1975 |
Problem with cache of filecache in OC is always a question: is this class always used for interfacing with filecache or in some places we do direct calls omitting this class. If yes than we should be safe from any desync. |
@mrow4a true, which is why this pr is limited to the getPathByID lookup. We are neither caching etags or full filecache rows nor are we caching them across requests. The path lookup is only cached per request and needs to be invalidated when a delete or rename operation happens. For a share mount/unmount the result actually does not need to be invalidated because the path is relative to the storage root, which remains the same. |
ah true, then yes this would work. |
https://github.com/owncloud/core/pull/28166/files has explored the places that are bypassing the Cache class. I don't see places that affect this cache:
|
lib/private/Files/Cache/Cache.php
Outdated
* and a single trip to the db is sufficient to answer subsequent calls. | ||
* @var CE[] $path_cache | ||
*/ | ||
private static $path_cache = []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better use a CappedMemoryCache (https://github.com/owncloud/core/blob/master/lib/private/Cache/CappedMemoryCache.php), so we have limited entries and don't overload the memory.
lib/private/Files/Cache/Cache.php
Outdated
@@ -979,3 +1002,14 @@ public function normalize($path) { | |||
return \trim(\OC_Util::normalizeUnicode($path), '/'); | |||
} | |||
} | |||
|
|||
class CE { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd use just an array and document the keys if needed.
@@ -324,6 +324,7 @@ public function insert($file, array $data) { | |||
* @param array $data [$key => $value] the metadata to update, only the fields provided in the array will be updated, non-provided values will remain unchanged | |||
*/ | |||
public function update($id, array $data) { | |||
unset(self::$path_cache[(int)$id]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we try to update the cache instead of removing the element?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
over optimisation in my opinion :>
@@ -507,6 +508,7 @@ public function inCache($file) { | |||
public function remove($file) { | |||
$entry = $this->get($file); | |||
if ($entry !== false) { | |||
unset(self::$path_cache[(int)$entry['fileid']]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should remove the cache after the operation. In case the operation fails, the cache will still have the value so we'll avoid a hit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
over optimisation in my opinion :>
The patch is in production as is. @jvillafanez feel free to take over the PR and polish it. |
8e7f2e4
to
6ba1d6b
Compare
This is ready to review again. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe not worth fixing one word in a comment, unless there are other reasons to change something or rebase...
I guess this is ready for final review? "This branch is 3 commits ahead, 102 commits behind master." And then request people again for review. (It looks OK to me) |
Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de>
b74af46
to
a9d3107
Compare
Kudos, SonarCloud Quality Gate passed! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
default for CappedMemoryCache not clear, and lots of (int) X casting. But overall looks good and logic approved earlier.
This PR significantly reduces the number of queries for
Cache::pathById()
lookups. This is less intrusive than a full cache implementation but it can at least cache and invalidate the id -> path lookup per request.Before:
After: