-
Notifications
You must be signed in to change notification settings - Fork 267
Fix: Cache key includes query parameters to prevent stale data after 422 errors #250
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…errors Co-authored-by: karpikpl <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes a critical caching bug where changing date ranges would show stale data after encountering 422 API errors. The root cause was that cache keys only used the endpoint path, causing all requests to the same endpoint to share cache entries regardless of query parameters.
Key changes:
- Updated cache key generation to include query parameters and Authorization header fingerprints
- Added cache clearing on errors to prevent stale data retention
- Removed caching from teams API to simplify the fix
- Enhanced error messaging for better user guidance
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.
Show a summary per file
File | Description |
---|---|
shared/utils/metrics-util.ts |
Core fix: implements auth-bound cache keys with query parameters and error-triggered cache clearing |
tests/metrics-cache.nuxt.spec.ts |
New tests for basic cache key generation logic with different query parameters |
tests/metrics-auth-cache.nuxt.spec.ts |
New tests for auth-bound cache key functionality and edge cases |
server/api/teams.ts |
Removes caching entirely from teams API to simplify the overall caching strategy |
app/components/MainComponent.vue |
Clears API errors on new requests and improves 422 error messaging |
Co-authored-by: Copilot <[email protected]>
Problem
When users change date ranges in the Copilot Metrics Viewer, the application would stop working correctly after encountering a 422 error (API limit reached). Specifically:
Root Cause
The caching mechanism in
shared/utils/metrics-util.ts
was using onlyevent.path
(e.g.,/api/metrics
) as the cache key, causing all requests to the same endpoint to share the same cache entry regardless of query parameters like date ranges.This meant that:
since=2024-01-01
vssince=2024-02-01
) used the same cache entrySolution
Updated cache key to include query parameters:
Added cache clearing on errors:
Clear API errors on new requests in the client:
Verification
The fix ensures that each unique combination of query parameters gets its own cache entry, preventing cross-contamination between different date ranges and eliminating stale data issues after API errors.
Fixes #249.
Warning
Firewall rules blocked me from connecting to one or more addresses
I tried to connect to the following addresses, but was blocked by firewall rules:
api.fontshare.com
node (vitest)
(dns block)node /home/REDACTED/work/copilot-metrics-viewer/copilot-metrics-viewer/node_modules/.bin/nuxt build
(dns block)api.fontsource.org
node (vitest)
(dns block)node /home/REDACTED/work/copilot-metrics-viewer/copilot-metrics-viewer/node_modules/.bin/nuxt build
(dns block)/usr/local/bin/node --enable-source-maps /home/REDACTED/work/copilot-metrics-viewer/copilot-metrics-viewer/node_modules/@nuxt/cli/bin/nuxi.mjs _dev
(dns block)fonts.bunny.net
node (vitest)
(dns block)node /home/REDACTED/work/copilot-metrics-viewer/copilot-metrics-viewer/node_modules/.bin/nuxt build
(dns block)/usr/local/bin/node --enable-source-maps /home/REDACTED/work/copilot-metrics-viewer/copilot-metrics-viewer/node_modules/@nuxt/cli/bin/nuxi.mjs _dev
(dns block)fonts.google.com
node (vitest)
(dns block)node /home/REDACTED/work/copilot-metrics-viewer/copilot-metrics-viewer/node_modules/.bin/nuxt build
(dns block)/usr/local/bin/node --enable-source-maps /home/REDACTED/work/copilot-metrics-viewer/copilot-metrics-viewer/node_modules/@nuxt/cli/bin/nuxi.mjs _dev
(dns block)fonts.googleapis.com
node (vitest 1)
(dns block)node (vitest 2)
(dns block)node (vitest 3)
(dns block)https://api.github.com/orgs/mocked-org/copilot/metrics
/usr/local/bin/node --enable-source-maps /home/REDACTED/work/copilot-metrics-viewer/copilot-metrics-viewer/node_modules/@nuxt/cli/bin/nuxi.mjs _dev
(http block)If you need me to access, download, or install something from one of these locations, you can either:
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.