-
Notifications
You must be signed in to change notification settings - Fork 9
feat(catalogs): artist_account_id filter + no-cap pagination on GET /api/catalogs/measurements #763
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
Open
sweetmantech
wants to merge
1
commit into
main
Choose a base branch
from
feat/catalog-measurements-artist-filter
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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 |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| import { describe, it, expect, vi, beforeEach } from "vitest"; | ||
| import { resolveCatalogSongsInScope } from "../resolveCatalogSongsInScope"; | ||
| import { selectCatalogSongTitles } from "@/lib/supabase/catalog_songs/selectCatalogSongTitles"; | ||
| import { selectSongArtistIsrcs } from "@/lib/supabase/song_artists/selectSongArtistIsrcs"; | ||
|
|
||
| vi.mock("@/lib/supabase/catalog_songs/selectCatalogSongTitles", () => ({ | ||
| selectCatalogSongTitles: vi.fn(), | ||
| })); | ||
| vi.mock("@/lib/supabase/song_artists/selectSongArtistIsrcs", () => ({ | ||
| selectSongArtistIsrcs: vi.fn(), | ||
| })); | ||
|
|
||
| const catalogId = "7d3e5c35-1fac-4b88-aa90-e2e4a52dfe78"; | ||
| const artistAccountId = "b1814076-8e19-4a77-9dea-2ec150e26aaa"; | ||
|
|
||
| const catalogSongs = [ | ||
| { isrc: "ISRC1", title: "Song One" }, | ||
| { isrc: "ISRC2", title: "Song Two" }, | ||
| { isrc: "ISRC3", title: "Song Three" }, | ||
| ]; | ||
|
|
||
| describe("resolveCatalogSongsInScope", () => { | ||
| beforeEach(() => vi.clearAllMocks()); | ||
|
|
||
| it("returns every catalog song when no artist filter is given", async () => { | ||
| vi.mocked(selectCatalogSongTitles).mockResolvedValue(catalogSongs); | ||
|
|
||
| const result = await resolveCatalogSongsInScope({ catalogId }); | ||
|
|
||
| expect(result).toEqual(catalogSongs); | ||
| expect(selectSongArtistIsrcs).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it("restricts to the catalog ∩ song_artists intersection when filtered", async () => { | ||
| vi.mocked(selectCatalogSongTitles).mockResolvedValue(catalogSongs); | ||
| // ISRC4 is linked to the artist but not in this catalog — must not leak in | ||
| vi.mocked(selectSongArtistIsrcs).mockResolvedValue(["ISRC1", "ISRC3", "ISRC4"]); | ||
|
|
||
| const result = await resolveCatalogSongsInScope({ catalogId, artistAccountId }); | ||
|
|
||
| expect(selectSongArtistIsrcs).toHaveBeenCalledWith(artistAccountId); | ||
| expect(result).toEqual([ | ||
| { isrc: "ISRC1", title: "Song One" }, | ||
| { isrc: "ISRC3", title: "Song Three" }, | ||
| ]); | ||
| }); | ||
|
|
||
| it("returns [] when the artist has no songs in the catalog", async () => { | ||
| vi.mocked(selectCatalogSongTitles).mockResolvedValue(catalogSongs); | ||
| vi.mocked(selectSongArtistIsrcs).mockResolvedValue(["OTHER1"]); | ||
|
|
||
| expect(await resolveCatalogSongsInScope({ catalogId, artistAccountId })).toEqual([]); | ||
| }); | ||
| }); |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| import { | ||
| selectCatalogSongTitles, | ||
| type CatalogSongTitle, | ||
| } from "@/lib/supabase/catalog_songs/selectCatalogSongTitles"; | ||
| import { selectSongArtistIsrcs } from "@/lib/supabase/song_artists/selectSongArtistIsrcs"; | ||
|
|
||
| /** | ||
| * Resolve the songs a catalog measurements read covers: the whole catalog, | ||
| * or — when an artist filter is applied — only the catalog's songs linked | ||
| * to that artist account (catalog_songs ∩ song_artists). Songs the artist | ||
| * is linked to outside the catalog never leak in. | ||
| * | ||
| * @param params.catalogId - The catalog to list songs for | ||
| * @param params.artistAccountId - Optional artist account to scope the read to | ||
| * @returns ISRC + title pairs in scope, or [] when nothing matches | ||
| */ | ||
| export async function resolveCatalogSongsInScope({ | ||
| catalogId, | ||
| artistAccountId, | ||
| }: { | ||
| catalogId: string; | ||
| artistAccountId?: string; | ||
| }): Promise<CatalogSongTitle[]> { | ||
| const songs = await selectCatalogSongTitles(catalogId); | ||
| if (!artistAccountId) return songs; | ||
|
|
||
| const artistIsrcs = new Set(await selectSongArtistIsrcs(artistAccountId)); | ||
| return songs.filter(song => artistIsrcs.has(song.isrc)); | ||
| } |
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.
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.
P2: Artist-scoped valuation can be skewed because the stream total is filtered to the artist while
catalog_age_yearsstill comes from the whole catalog. Consider resolving the earliest release date from the scoped song set (or a scoped album/source lookup) whenartist_account_idis provided.Prompt for AI agents