-
Notifications
You must be signed in to change notification settings - Fork 0
β‘ Bolt: Optimize getPlaylistWithSongs with innerJoin #59
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
Krosebrook
merged 1 commit into
main
from
bolt-optimize-playlist-songs-10277146025077263821
Mar 3, 2026
Merged
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -160,22 +160,11 @@ export class DatabaseStorage implements IStorage { | |
| const playlist = await this.getPlaylist(id); | ||
| if (!playlist) return undefined; | ||
|
|
||
| const playlistSongRows = await db.select({ songId: playlistSongs.songId }) | ||
| .from(playlistSongs) | ||
| .where(eq(playlistSongs.playlistId, id)); | ||
|
|
||
| const songIds = playlistSongRows.map(r => r.songId).filter(id => typeof id === 'number' && !isNaN(id)); | ||
|
|
||
| if (songIds.length === 0) { | ||
| return { ...playlist, songs: [] }; | ||
| } | ||
|
|
||
| const songsResult = await db.select() | ||
| const songsList = await db.select(getTableColumns(songs)) | ||
| .from(songs) | ||
| .where(inArray(songs.id, songIds)); | ||
|
|
||
| const songMap = new Map(songsResult.map(s => [s.id, s])); | ||
| const songsList = songIds.map(id => songMap.get(id)).filter((s): s is Song => !!s); | ||
| .innerJoin(playlistSongs, eq(songs.id, playlistSongs.songId)) | ||
| .where(eq(playlistSongs.playlistId, id)) | ||
| .orderBy(playlistSongs.addedAt); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P3: The Prompt for AI agents |
||
|
|
||
| return { ...playlist, songs: songsList }; | ||
| } | ||
|
|
||
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.
The current implementation orders songs by
addedAtin ascending order (oldest first). This might not be the most intuitive user experience, as users often expect to see their most recently added songs first. Consider changing to descending order for better usability and consistency withgetLikedSongs. This also allows explicitly handlingNULLvalues foraddedAtsincedescis already imported. TheaddedAtcolumn can beNULLas it's not defined withnotNull()in the schema.