embed_docsite: replace per-directory GitHub fetch with Trees API + cache - #618
Open
IZO-Ong wants to merge 8 commits into
Open
embed_docsite: replace per-directory GitHub fetch with Trees API + cache#618IZO-Ong wants to merge 8 commits into
IZO-Ong wants to merge 8 commits into
Conversation
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.
Short Description
Replaces
embed_docsite's per-directory GitHub Contents API walk with a single Trees API call with an on-disk cache keyed by ETag and per-file blob SHA, cutting a full run of ~60 GitHub API requests down to 2.Fixes #182
Implementation Details
github_utils.pyused to fetchdocs/andadaptors/fromOpenFn/docsby recursing into every directory via the Contents API (GET /repos/{owner}/{repo}/contents/{path}) with one request per directory, then downloading each file'sdownload_urlseparately. On the full corpus that is about one request per directory (~60), which is easy to exhaust GitHub's unauthenticated 60/hr rate limit.#182 proposed fixing this with
git clone --depth 1. This PR takes a different route by using GitHub Trees API (GET /repos/OpenFn/docs/git/trees/main?recursive=1), which returns the entire file tree, path and blob SHA for every file in one request, plus a persistent on-disk cache (services/embed_docsite/docsite_cache/, gitignored) that stores the tree's ETag and each cached file's blob SHA.general_docs+adaptor_docs+adaptor_functions) now spends 2 GitHub API requests — one conditional Trees request per markdown docs_type. Measured against the live repo: both come back304when nothing changed, and 0 files are re-downloaded. Only files whose blob SHA actually moved get re-fetched, fromraw.githubusercontent.com, which is not rate-limited.503 UPSTREAM_ERROR). A cached file missing from disk degrades to anApolloErrorinstead of anunhandled
FileNotFoundError.GITHUB_TOKEN(in.env.example) to the docs fetch, raising the limit from 60 to 5000 requests/hour.{"refresh_cache_only": true}warms both caches without needing Pinecone/OpenAI keys, for pre-warming in CI or locally.get_repo_treeraises if GitHub reports the tree astruncated(~100,000 files from Github's API). Not a concern atOpenFn/docs' current size (702 files).Tests: unit tests fully mocked (
services/embed_docsite/tests/unit/), plus integration tests over the real cached corpus(
services/embed_docsite/tests/integration/test_docsite_cache_corpus.py, skipped unless the cache is warmed).AI Usage
Please disclose whether you've used AI in this work (it's cool, we just want to know!):
You can read more details in our
Responsible AI Policy