Skip to content

fs.find: cache path ids #286

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

Merged
merged 1 commit into from
Jun 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions pydrive2/fs/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,11 @@ def find(self, path, detail=False, **kwargs):
bucket, base = self.split_path(path)

seen_paths = set()
cached = base in self._ids_cache["dirs"]
if not cached:
dir_ids = self._path_to_item_ids(base)
self._cache_path_id(base, *dir_ids)

dir_ids = [self._ids_cache["ids"].copy()]
Copy link
Member

Choose a reason for hiding this comment

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

sorry, coming back here to double check :) one potential race condition here is if _cache_path_id that is being executed in some other thread got to the point where is update the first dictionary, but not yet the second. In this case dir_ids might not contain the cache for base yet.

Copy link
Member Author

Choose a reason for hiding this comment

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

With base, do you mean the root of the filesystem (aka self.base) or the path passed in find (aka base here)?

Copy link
Member

Choose a reason for hiding this comment

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

I mean the local var base value.

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah, looks like we need to lock self._cache_path_id.

Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe it'd have been okay if we used dirs here instead of ids. But I went with locking in #289.

contents = []
while dir_ids:
Expand Down