-
Notifications
You must be signed in to change notification settings - Fork 83
Add intelligent cache revalidation #8
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
0adfa06
Add intelligent cache revalidation
TianqiZhang 6b035ec
Handle structured session locations
TianqiZhang 4251424
Clarify refresh revalidation progress
TianqiZhang 42f7b7c
Address cache revalidation review feedback
TianqiZhang c174c62
Reduce cache revalidation IO
TianqiZhang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1,60 @@ | ||
| import { KNOWN_EVENTS } from '../config.js'; | ||
| import { getAllCachedSessions, fetchAndCache } from '../data/cache.js'; | ||
| import { | ||
| fetchAndCache, | ||
| getAllCachedSessions, | ||
| isCacheCheckDue, | ||
| readMeta, | ||
| readSessions, | ||
| } from '../data/cache.js'; | ||
| import type { Session } from '../contracts.js'; | ||
| import { FetchError } from '../errors.js'; | ||
|
|
||
| export async function ensureCache(): Promise<void> { | ||
| const sessions = await getAllCachedSessions(); | ||
| if (sessions.length === 0) { | ||
| process.stderr.write('No cached sessions. Fetching...\n'); | ||
| for (const event of KNOWN_EVENTS) { | ||
| try { | ||
| export async function ensureCache(): Promise<Session[]> { | ||
| let missingCacheHeaderPrinted = false; | ||
| const availableSessions: Session[] = []; | ||
|
|
||
| for (const event of KNOWN_EVENTS) { | ||
| const cachedSessions = await readSessions(event.id); | ||
| const meta = await readMeta(event.id); | ||
| const isMissingCache = cachedSessions.length === 0; | ||
|
TianqiZhang marked this conversation as resolved.
|
||
|
|
||
| if (!isMissingCache && !isCacheCheckDue(meta)) { | ||
| availableSessions.push(...cachedSessions); | ||
| continue; | ||
| } | ||
|
|
||
| try { | ||
| if (isMissingCache) { | ||
| if (!missingCacheHeaderPrinted) { | ||
| process.stderr.write('Fetching missing session caches...\n'); | ||
| missingCacheHeaderPrinted = true; | ||
| } | ||
| process.stderr.write(` ${event.name}...`); | ||
| const fetched = await fetchAndCache(event); | ||
| } | ||
|
|
||
| const fetched = await fetchAndCache(event, { | ||
| cachedMeta: meta, | ||
| cachedSessions, | ||
| }); | ||
| availableSessions.push(...fetched); | ||
| if (isMissingCache) { | ||
| process.stderr.write(` ${fetched.length} sessions.\n`); | ||
| } catch { | ||
| process.stderr.write(' unavailable.\n'); | ||
| } | ||
| } catch (err) { | ||
| if (!(err instanceof FetchError)) { | ||
| throw err; | ||
| } | ||
|
|
||
| if (isMissingCache) { | ||
| process.stderr.write(` unavailable: ${err.message}\n`); | ||
| } else { | ||
| availableSessions.push(...cachedSessions); | ||
| process.stderr.write(`Could not refresh ${event.name}; using cached sessions.\n`); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return availableSessions.length > 0 | ||
| ? availableSessions | ||
| : getAllCachedSessions(); | ||
| } | ||
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.