chore(reorder-debug): add server/client logs for move and playlist order slice to diagnose ordering issue

This commit is contained in:
Geert Rademakes 2025-08-08 14:37:45 +02:00
parent 484d191201
commit e2d6d55433
3 changed files with 6 additions and 1 deletions

View File

@ -154,6 +154,8 @@ router.post('/reorder-move', async (req: Request, res: Response) => {
if (insertIndex < 0) insertIndex = without.length; if (insertIndex < 0) insertIndex = without.length;
without.splice(insertIndex, 0, fromId); without.splice(insertIndex, 0, fromId);
console.log('[REORDER_MOVE] playlist:', playlistName, 'from:', fromId, 'to:', toId, 'baseLen:', base.length, 'orderLenBefore:', order.length, 'orderLenAfter:', without.length);
console.log('[REORDER_MOVE] sample order:', without.slice(0, 5));
node.order = without; // store full order overlay node.order = without; // store full order overlay
updated = true; updated = true;
return node; return node;

View File

@ -126,7 +126,8 @@ router.get('/playlist/*', async (req: Request, res: Response) => {
}; };
const trackIds = getAllTrackIds(playlist); const trackIds = getAllTrackIds(playlist);
console.log(`Found ${trackIds.length} tracks in playlist "${playlistName}"`); console.log(`[PLAYLIST_ORDER] ${playlistName} tracks count:`, trackIds.length);
console.log('[PLAYLIST_ORDER] first 10 ids:', trackIds.slice(0, 10));
if (trackIds.length === 0) { if (trackIds.length === 0) {
return res.json({ return res.json({
@ -177,6 +178,7 @@ router.get('/playlist/*', async (req: Request, res: Response) => {
const pageEnd = Math.min(pageStart + limit, trackIds.length); const pageEnd = Math.min(pageStart + limit, trackIds.length);
const pageTrackIds = trackIds.slice(pageStart, pageEnd); const pageTrackIds = trackIds.slice(pageStart, pageEnd);
console.log('[PLAYLIST_ORDER] page', page, 'limit', limit, 'slice', pageStart, pageEnd, 'ids:', pageTrackIds);
const pageSongs = await Song.find({ id: { $in: pageTrackIds } }) const pageSongs = await Song.find({ id: { $in: pageTrackIds } })
.populate('s3File.musicFileId') .populate('s3File.musicFileId')
.lean(); .lean();

View File

@ -299,6 +299,7 @@ export const PaginatedSongList: React.FC<PaginatedSongListProps> = memo(({
} }
const toId = songs[index].id; const toId = songs[index].id;
// Simpler and more robust: instruct backend to move fromId before toId // Simpler and more robust: instruct backend to move fromId before toId
console.debug('[Reorder] move request', { playlist: currentPlaylist, fromId, toId });
await api.moveTrackInPlaylist(currentPlaylist, fromId, toId); await api.moveTrackInPlaylist(currentPlaylist, fromId, toId);
await onReorder(songs.map(s => s.id)); // trigger refresh via parent await onReorder(songs.map(s => s.id)); // trigger refresh via parent
setDragHoverIndex(null); setDragHoverIndex(null);