Repository navigation
Answer info() for a path from the name lookup, without a second request - #467
Draft
shcheklein wants to merge 3 commits into
Draft
shcheklein wants to merge 3 commits into
shcheklein wants to merge 3 commits into
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The lookup already returns the type, size and checksum that info() reports, so the metadata read after it is dropped. size(), isfile() and isdir() go through info() and save the same request. A folder the filesystem already knows needs no request, as in exists(). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are recorded for the change reducing redundant Drive metadata requests.
No open issues 🎉
What changed in this PR
Reduces Drive requests for path-based info() and related filesystem methods by reusing name-lookup metadata and cached folders, while preserving root metadata reads.
Changes:
- Removes the second metadata request for non-root paths.
- Adds live tests for request counts and metadata consistency.
- Updates offline expectations and root metadata retry coverage.
| File | Description |
|---|---|
pydrive2/test/test_fs.py |
Adds live request-count and metadata consistency tests. |
pydrive2/test/test_fs_unit.py |
Updates request expectations and retry coverage. |
pydrive2/fs/spec.py |
Returns path information from lookup results or cached folders. |
Review effort: Balanced
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fs.info(path)looked the name up in its folder and then read the file's metadata with a second request. The lookup already asks Drive for everythinginfo()reports (type, size and MD5 checksum), so the second request is gone.size(),isfile()andisdir()all go throughinfo(), so they save the same request.A folder the filesystem already knows is answered from its folder cache, as
exists()andls()already are. So a folder another client deleted keeps showing as a directory untilinvalidate_cache(), as it does inexists().Unchanged:
root,appDataFolder) and trashed roots still read metadata, as before.Tests:
test_stat_after_a_write_sends_at_most_the_name_lookup(live, 8 cases) counts the Drive calls ofinfo,size,isfileandisdiron a file and on a folder. Run on main's code against real Drive, all 8 fail (['drive.files.list', 'drive.files.get']for a file,['drive.files.get']for a folder) (run).test_info_after_creating_files_in_the_root_matches_their_metadata(live) checksinfo()of a plain file, a Google Doc and a shortcut against Drive's metadata for their IDs, which is whatinfo()read before. It passes on main's code too, as it should.test_info_repeats_a_metadata_read_that_timed_outnow times out the read that remains:info("root").This touches
info()inpydrive2/fs/spec.py, which #451, #455 and #456 also edit. Whichever merges later may need a small rebase.🤖 Generated with Claude Code