Repository navigation
Conversation
Introduce a platform independent metrics structure with own episode ids, platform id mappings and podcast/episode metrics stored by date range. Spotify streams are written as daily and lifetime plays alongside v1, existing history is backfilled in migration 19 and exposed via /analytics/v2 queries. Also apply the podcast access check to all API versions, return after 401 responses and await migrations on startup. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Member
|
As discussed, there are a couple of downsides:
We decided to go with separate tables (and not all metrics in one). |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
First step of a platform-independent schema and API v2, validated with one metric: Spotify plays. Plays are Spotify
streams, meaning 60 seconds or more.Schema (migration 19 +
schema.sql)platforms: spotify, apple, anchor, podigee.metrics:plays, with anadditiveflag. Unique metrics, such as listeners, will later be stored withadditive=0and never summed.episodes: ownINT UNSIGNED AUTO_INCREMENTIDs, unique across the database. The podcast ID stayspodcasts.account_id.podcastPlatformIdsandepisodePlatformIdsmap our IDs to each platform's IDs.podcastMetricsandepisodeMetricsstore a value per(id, metric, platform, start_date, end_date).spotify{Podcast,Episode}DetailedStreamshistory and assigns episode IDs to all known Spotify episodes.Why auto-increment instead of UUIDs:
BINARY(16)adds about 12 bytes per row and per secondary index entry, roughly 1.2 GB or more.Write path
SpotifyConnectorkeeps its v1 writes and also writes to v2:detailedStreams: daily plays, at podcast or episode level.metadataandepisodeMetadata: lifetime plays and platform ID mappings.Writes are single bulk upserts, so refetching days to fill gaps is idempotent.
Read API
The new queries in
db_schema/queries/v2/go through the existing/analytics/:version/:podcastId/:queryroute:podcastPlays,podcastPlaysTotalandpodcastPlaysLifetime. The total includesdays, the number of days with data.episodePlays,episodePlaysTotalandepisodePlaysLifetime.episodes: our episode IDs mapped to platform IDs and names.podcastPlaysMissingDays: days with no data, for gap filling.Each row is
{podcastId|episodeId, metric, platform, startDate, endDate, value}.The API docs now cover v1 and v2.
make dev-sqlandmake send-analytics-%take an optionalVERSION.Fixes along the way
/analyticsonly ran forv1, so v2 would have been open to any podcast.return, so the handler kept running after sending the error.DBInitializerdidn'tawaiteach migration. Note that a migration file name must not contain digits after its number, otherwise the file is not found.Review notes
INSERT ... SELECT. Expect it to take a while during the first deploy.Test plan
make test: 64 unit tests pass, including the newMetricsRepositoryandSpotifyConnectortests.schema.sql: the migrations maximum is 19 and the seed rows are present.tests/api_e2e/analytics_v2.test.js: 9/9 pass. This was run against a separate DB and port (API_BASE_URLoverride), not throughmake e2e-tests.make e2e-testsin the standard setup.🤖 Generated with Claude Code