From f345b83165db7ced21961ae9863f0b261d03998b Mon Sep 17 00:00:00 2001 From: Sam Levang <39069044+slevang@users.noreply.github.com> Date: Fri, 23 Jun 2023 10:12:16 -0400 Subject: [PATCH] Faster cache in `find` (#561) * use dict instead of list * convert cache dicts back to list --- gcsfs/core.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/gcsfs/core.py b/gcsfs/core.py index 28cf61a6..bbb31271 100644 --- a/gcsfs/core.py +++ b/gcsfs/core.py @@ -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"])