From a941e030371ab2c37fc3f8707a3debcb369c20be Mon Sep 17 00:00:00 2001 From: Aly Raffauf Date: Wed, 29 Jul 2026 17:45:27 -0400 Subject: [PATCH] Stop prefetching repository directories --- src/hooks/useRepoTree.ts | 37 +------------------------------------ 1 file changed, 1 insertion(+), 36 deletions(-) diff --git a/src/hooks/useRepoTree.ts b/src/hooks/useRepoTree.ts index 1ad1c71..8902fcd 100644 --- a/src/hooks/useRepoTree.ts +++ b/src/hooks/useRepoTree.ts @@ -1,9 +1,7 @@ import type { $output as RepoTreeResponse } from '@atcute/tangled/types/repo/tree' import { useEffect, useRef, useState } from 'react' import type { Repo } from '../lib/tangled' -import { getRepoTree, isDirectoryMode } from '../lib/tangled/repo' - -const MAX_PREFETCHED_DIRECTORIES = 3 +import { getRepoTree } from '../lib/tangled/repo' type UseRepoTreeOptions = { initialTree?: RepoTreeResponse @@ -13,13 +11,11 @@ type UseRepoTreeOptions = { export function useRepoTree({ initialTree, path, repo }: UseRepoTreeOptions) { const cache = useRef(new Map()) - const prefetching = useRef(new Set()) const [tree, setTree] = useState(initialTree ?? null) const [error, setError] = useState(null) useEffect(() => { cache.current.clear() - prefetching.current.clear() if (initialTree !== undefined) { cache.current.set('', initialTree) @@ -36,7 +32,6 @@ export function useRepoTree({ initialTree, path, repo }: UseRepoTreeOptions) { if (cachedTree !== undefined) { setTree(cachedTree) setError(null) - void prefetchDirectories(repo, cachedTree, path, cache.current, prefetching.current) return } @@ -50,7 +45,6 @@ export function useRepoTree({ initialTree, path, repo }: UseRepoTreeOptions) { if (!isCancelled) { setTree(response) - void prefetchDirectories(repo, response, path, cache.current, prefetching.current) } } catch (caught) { if (!isCancelled) { @@ -68,32 +62,3 @@ export function useRepoTree({ initialTree, path, repo }: UseRepoTreeOptions) { return { error, tree } } - -async function prefetchDirectories( - repo: Repo, - tree: RepoTreeResponse, - currentPath: string, - cache: Map, - prefetching: Set, -): Promise { - const directories = tree.files - .filter((entry) => isDirectoryMode(entry.mode)) - .map((entry) => (currentPath ? `${currentPath}/${entry.name}` : entry.name)) - .slice(0, MAX_PREFETCHED_DIRECTORIES) - - await Promise.all( - directories.map(async (directoryPath) => { - if (cache.has(directoryPath) || prefetching.has(directoryPath)) return - - prefetching.add(directoryPath) - try { - const childTree = await getRepoTree(repo, directoryPath) - cache.set(directoryPath, childTree) - } catch { - // Navigation retries directories whose background prefetch failed. - } finally { - prefetching.delete(directoryPath) - } - }), - ) -} -- 2.51.2