Skip to content

Answer info() for a path from the name lookup, without a second request - #467

Draft
shcheklein wants to merge 3 commits into
mainfrom
info-from-the-lookup
Draft

shcheklein wants to merge 3 commits into
mainfrom
info-from-the-lookup

Conversation

@shcheklein

Copy link
Copy Markdown
Member

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 everything info() reports (type, size and MD5 checksum), so the second request is gone. size(), isfile() and isdir() all go through info(), so they save the same request.

fs.size("root/data/a.csv")     # 2 requests before, 1 now
fs.isfile("root/data/a.csv")   # 2 requests before, 1 now
fs.isdir("root/data")          # 1 request before (metadata by the cached ID), 0 now
By path Before After
file name lookup + metadata read name lookup
folder the filesystem knows metadata read no request
folder it doesn't know yet name lookups + metadata read name lookups

A folder the filesystem already knows is answered from its folder cache, as exists() and ls() already are. So a folder another client deleted keeps showing as a directory until invalidate_cache(), as it does in exists().

Unchanged:

  • the entries: same name, type, size and checksum for regular files, folders, Google Docs and shortcuts;
  • which item answers when names are shared (the lowest ID);
  • a mount's own root (bare file ID, bare folder ID, 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 of info, size, isfile and isdir on 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) checks info() of a plain file, a Google Doc and a shortcut against Drive's metadata for their IDs, which is what info() read before. It passes on main's code too, as it should.
  • 22 offline tests that counted the metadata read now expect the lookup alone. test_info_repeats_a_metadata_read_that_timed_out now times out the read that remains: info("root").

This touches info() in pydrive2/fs/spec.py, which #451, #455 and #456 also edit. Whichever merges later may need a small rebase.

🤖 Generated with Claude Code

shcheklein and others added 2 commits December 4, 2026 18:18
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>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 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

No deployments
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.

2 participants