Skip to content

Commit

Permalink
Faster cache in find (#561)
Browse files Browse the repository at this point in the history
* use dict instead of list

* convert cache dicts back to list
  • Loading branch information
slevang committed Jun 23, 2023
1 parent d7952a9 commit f345b83
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions gcsfs/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1254,15 +1254,17 @@ async def _find(
"size": 0,
}

listing = cache_entries.setdefault(parent, [])
if previous not in listing:
listing.append(previous)
listing = cache_entries.setdefault(parent, {})
name = previous["name"]
if name not in listing:
listing[name] = previous

previous = dirs[parent]
parent = self._parent(parent)

if not prefix:
self.dircache.update(cache_entries)
cache_entries_list = {k: list(v.values()) for k, v in cache_entries.items()}
self.dircache.update(cache_entries_list)

if withdirs:
objects = sorted(objects + list(dirs.values()), key=lambda x: x["name"])
Expand Down

0 comments on commit f345b83

Please sign in to comment.