Skip to content

Bug 2055001 - Github Pull Requests: Look for etag value before fetching pull request data to cut down on rate limiting#2672

Open
dklawren wants to merge 2 commits into
mozilla-bteam:masterfrom
dklawren:2055001
Open

Bug 2055001 - Github Pull Requests: Look for etag value before fetching pull request data to cut down on rate limiting#2672
dklawren wants to merge 2 commits into
mozilla-bteam:masterfrom
dklawren:2055001

Conversation

@dklawren

Copy link
Copy Markdown
Collaborator

Changes

lib/Constants.pm

  • GITHUB_CACHE_SECONDS: 300 → 900 (15-min freshness window), with an updated comment explaining revalidation is now cheap.
  • Added GITHUB_REVALIDATE_SECONDS => 86_400 (24h hard memcached TTL so ETags outlive the freshness window), and exported it.
  • Left GITHUB_ERROR_CACHE_SECONDS at 60.

lib/API/V1/PullRequests.pm

  • Versioned cache wrapper under a new github_pr.v2. key prefix. The stored value is now { pr_data, pr_etag, reviews_etag, fresh_until }, written with a hard TTL of GITHUB_REVALIDATE_SECONDS; freshness is tracked in-band via fresh_until. Old bare-$pr_data entries are simply ignored and expire on their own.
  • Rewrote _fetch_pull_request into three paths: fresh hit (serve, zero calls), stale-hit-with-etags (revalidate), and miss/no-etags (full fetch).
  • New _revalidate_pull_request does conditional GETs on both the PR and reviews endpoints — reusing cached fields on 304, recomputing on 200, treating a PR error as fatal (→ inaccessible) and a reviews error as non-fatal (→ empty), matching current behavior.
  • _github_get gained conditional-request support ($etag arg → If-None-Match), returning { ok, not_modified, status, etag, data }. It explicitly treats HTTP 304 as success and carries the echoed ETag through.
  • New _warn_fetch_failure classifies failures for logging: 401/403 → auth/permission message (token problem), 404 → not-found/private message, anything else → the original generic warning. Applied at both the PR and reviews failure sites.
  • Extracted _pr_summary_fields and _store_wrapper helpers.

Behavior visible to users is unchanged; the API shape is identical.

…ng pull request data to cut down on rate limiting

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds ETag-based GitHub PR cache revalidation to reduce API rate-limit consumption.

Changes:

  • Introduces separate freshness and hard cache TTLs.
  • Adds conditional PR/review requests and versioned cache wrappers.
  • Improves GitHub failure logging.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
extensions/GitHubPullRequests/lib/Constants.pm Defines cache freshness and revalidation TTLs.
extensions/GitHubPullRequests/lib/API/V1/PullRequests.pm Implements ETag caching, revalidation, and failure classification.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread extensions/GitHubPullRequests/lib/API/V1/PullRequests.pm
Comment thread extensions/GitHubPullRequests/lib/API/V1/PullRequests.pm
Comment thread extensions/GitHubPullRequests/lib/API/V1/PullRequests.pm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants