Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 4 additions & 15 deletions server/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The current implementation orders songs by addedAt in 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 with getLikedSongs. This also allows explicitly handling NULL values for addedAt since desc is already imported. The addedAt column can be NULL as it's not defined with notNull() in the schema.

Suggested change
.orderBy(playlistSongs.addedAt);
.orderBy(desc(playlistSongs.addedAt).nullsLast());

Copy link

@cubic-dev-ai cubic-dev-ai bot Feb 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3: The addedAt column can be NULL based on the schema definition, but this orderBy clause doesn't explicitly handle NULL values. Consider using .nullsLast() or .nullsFirst() to ensure consistent ordering behavior regardless of the database's default NULL sorting.

Prompt for AI agents
Check if this issue is valid β€” if so, understand the root cause and fix it. At server/storage.ts, line 167:

<comment>The `addedAt` column can be `NULL` based on the schema definition, but this `orderBy` clause doesn't explicitly handle NULL values. Consider using `.nullsLast()` or `.nullsFirst()` to ensure consistent ordering behavior regardless of the database's default NULL sorting.</comment>

<file context>
@@ -160,22 +160,11 @@ export class DatabaseStorage implements IStorage {
-    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);
 
     return { ...playlist, songs: songsList };
</file context>
Fix with Cubic


return { ...playlist, songs: songsList };
}
Expand Down