Skip to content

Commit a594905

Browse files
committed
perf(github): Cache only required fields for accessible repos
Strip raw GitHub repo dicts down to the 5 fields used by get_repositories before storing in the cache. Reduces per-integration cache size from ~3KB per repo to ~100 bytes.
1 parent d642bfb commit a594905

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/sentry/integrations/github/client.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,18 +550,25 @@ def get_repos(self, page_number_limit: int | None = None) -> list[dict[str, Any]
550550
page_number_limit=page_number_limit,
551551
)
552552

553+
# Fields from the GitHub API response needed by get_repositories().
554+
_CACHED_REPO_FIELDS = ("id", "name", "full_name", "default_branch", "archived")
555+
553556
def get_accessible_repos_cached(self, ttl: int = 300) -> list[dict[str, Any]]:
554557
"""
555558
Return all repos accessible to this installation.
556559
Cached in Django cache for ``ttl`` seconds so that debounced
557560
search keystrokes don't re-fetch all pages from GitHub.
561+
562+
Only the fields used by get_repositories() are stored to keep
563+
the cache payload small.
558564
"""
559565
cache_key = f"github:accessible_repos:{self.integration.id}"
560566
cached = default_cache.get(cache_key)
561567
if cached is not None:
562568
return cached
563569

564-
repos = self.get_repos()
570+
all_repos = self.get_repos()
571+
repos = [{k: r.get(k) for k in self._CACHED_REPO_FIELDS} for r in all_repos]
565572
default_cache.set(cache_key, repos, ttl)
566573
return repos
567574

0 commit comments

Comments
 (0)