Skip re-fetching tracks, albums, and artists that are already fresh in the DB - #194
Closed
jbrown1618 with Copilot wants to merge 2 commits into
Closed
Skip re-fetching tracks, albums, and artists that are already fresh in the DB#194jbrown1618 with Copilot wants to merge 2 commits into
jbrown1618 with Copilot wants to merge 2 commits into
Conversation
…resh data Co-authored-by: jbrown1618 <9657751+jbrown1618@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Optimize data fetching for tracks, albums, and artists
Skip re-fetching tracks, albums, and artists that are already fresh in the DB
Feb 25, 2026
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.
Every Spotify sync re-fetched full details for all tracks, albums, and artists regardless of whether that data already existed. This adds a
last_updatedtimestamp to those three tables and skips Spotify API calls for records updated within the last 7 days.Schema
last_updated TIMESTAMP DEFAULT current_timestamptotrack,album, andartisttablesv016_add_last_updatedadds the columns to existing DBs; existing rows getcurrent_timestampas their initial value, so they're treated as fresh for the first week post-migrationFetch logic (
save_spotify_data.py)load_fresh_uris()queries the DB at sync start and populatesfresh_tracks,fresh_albums,fresh_artistssetsprocess_track()skips adding stale track data totracks_data/track_artistfor fresh tracks, but still queues their albums and artists for independent freshness evaluationqueue_album()/queue_artist()short-circuit if the URI is in the fresh set — no API call is made for themtrack_data(),album_data(),artist_data()now includelast_updated = datetime.now(timezone.utc)so the timestamp is refreshed on every upsertThe staleness window is controlled by
staleness_days = 7.Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.