-
Notifications
You must be signed in to change notification settings - Fork 1
Move watchlist caching to R2 and add Stremio E2E coverage #44
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
13 commits
Select commit
Hold shift + click to select a range
bf29f69
chore(release): v1.6.1 [skip ci]
github-actions[bot] 8d35b2a
Merge pull request #41 from leo-mathurin/staging
leo-mathurin 41d5748
chore(release): v1.7.0 [skip ci]
github-actions[bot] 92fcc73
feat(e2e): add Stremio end-to-end test harness
leo-mathurin 6489176
fix(e2e): address Greptile review findings
leo-mathurin 5064df8
fix(e2e): include all persisted test users in cleanup
leo-mathurin 0843152
test(e2e): run full suite by default
leo-mathurin c51b3e9
feat(cache): move watchlist cache to Cloudflare R2
leo-mathurin 548f452
chore: merge Stremio E2E CI harness
leo-mathurin ff1c0fb
test(e2e): exercise R2 cache with local MinIO
leo-mathurin 5fd0c0a
fix: address Greptile review feedback
leo-mathurin 12f05d8
fix(cache): make cache deletion race-safe
leo-mathurin 674537e
fix(cache): refresh stale R2 manifests
leo-mathurin 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
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
73 changes: 73 additions & 0 deletions
73
apps/backend/src/__tests__/helpers/mock-watchlist-cache.ts
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 |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| import type { StremioMeta, WatchlistData } from "@stremlist/shared"; | ||
|
|
||
| interface Entry { | ||
| data: WatchlistData; | ||
| cachedAt: Date; | ||
| generation: string; | ||
| } | ||
|
|
||
| class InMemoryWatchlistCache { | ||
| private entries = new Map<string, Entry>(); | ||
|
|
||
| reset(): void { | ||
| this.entries.clear(); | ||
| } | ||
|
|
||
| seed(watchlistId: string, metas: StremioMeta[], cachedAt = new Date()): void { | ||
| this.entries.set(watchlistId, { | ||
| data: { metas: structuredClone(metas) }, | ||
| cachedAt, | ||
| generation: `${watchlistId}:${cachedAt.toISOString()}`, | ||
| }); | ||
| } | ||
|
|
||
| get(watchlistId: string): Entry | null { | ||
| return this.entries.get(watchlistId) ?? null; | ||
| } | ||
|
|
||
| delete(watchlistId: string): void { | ||
| this.entries.delete(watchlistId); | ||
| } | ||
| } | ||
|
|
||
| export const cache = new InMemoryWatchlistCache(); | ||
|
|
||
| export function getCachedWatchlist(watchlistId: string): Promise<Entry | null> { | ||
| return Promise.resolve(cache.get(watchlistId)); | ||
| } | ||
|
|
||
| export function writeCachedWatchlist( | ||
| watchlistId: string, | ||
| watchlistData: WatchlistData, | ||
| cachedAt = new Date(), | ||
| ): Promise<string> { | ||
| const seen = new Set<string>(); | ||
| const metas = watchlistData.metas.filter((meta) => { | ||
| const key = `${meta.type}:${meta.id}`; | ||
| if (seen.has(key)) return false; | ||
| seen.add(key); | ||
| return true; | ||
| }); | ||
| if (metas.length === 0) cache.delete(watchlistId); | ||
| else cache.seed(watchlistId, metas, cachedAt); | ||
| return Promise.resolve(`${watchlistId}:${cachedAt.toISOString()}`); | ||
| } | ||
|
|
||
| export function findCachedMeta( | ||
| watchlistIds: string[], | ||
| type: string, | ||
| id: string, | ||
| ): Promise<StremioMeta | null> { | ||
| for (const watchlistId of watchlistIds) { | ||
| const found = cache | ||
| .get(watchlistId) | ||
| ?.data.metas.find((meta) => meta.type === type && meta.id === id); | ||
| if (found) return Promise.resolve(found); | ||
| } | ||
| return Promise.resolve(null); | ||
| } | ||
|
|
||
| export function deleteCachedWatchlist(watchlistId: string): Promise<void> { | ||
| cache.delete(watchlistId); | ||
| return Promise.resolve(); | ||
| } |
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.