修复当前播放的音乐记录置底
This commit is contained in:
+1
-1
@@ -749,7 +749,7 @@ export class D1Storage implements IStorage {
|
||||
try {
|
||||
const results = await this.db
|
||||
// 按队列顺序返回;当前播放项由最大 last_played_at 决定
|
||||
.prepare('SELECT * FROM music_v2_history WHERE username = ? ORDER BY created_at ASC, last_played_at ASC')
|
||||
.prepare('SELECT * FROM music_v2_history WHERE username = ? ORDER BY created_at ASC, id ASC')
|
||||
.bind(userName)
|
||||
.all();
|
||||
|
||||
|
||||
@@ -1404,7 +1404,7 @@ export class PostgresStorage implements IStorage {
|
||||
try {
|
||||
const results = await this.db
|
||||
// 按队列顺序返回;当前播放项由最大 last_played_at 决定
|
||||
.prepare('SELECT * FROM music_v2_history WHERE username = $1 ORDER BY created_at ASC, last_played_at ASC')
|
||||
.prepare('SELECT * FROM music_v2_history WHERE username = $1 ORDER BY created_at ASC, id ASC')
|
||||
.bind(userName)
|
||||
.all();
|
||||
|
||||
|
||||
@@ -807,11 +807,12 @@ export abstract class BaseRedisStorage implements IStorage {
|
||||
return Object.values(rows || {})
|
||||
.filter(Boolean)
|
||||
.map(value => JSON.parse(value as string) as MusicV2HistoryRecord)
|
||||
// 按队列顺序返回;当前播放项由最大 lastPlayedAt 决定
|
||||
// 按队列顺序返回;当前播放项由最大 lastPlayedAt 决定。
|
||||
// createdAt 相同时使用歌曲标识做稳定兜底,避免最近播放时间把歌曲顶到队尾。
|
||||
.sort((a, b) => {
|
||||
const createdAtDiff = (a.createdAt || 0) - (b.createdAt || 0);
|
||||
if (createdAtDiff !== 0) return createdAtDiff;
|
||||
return (a.lastPlayedAt || 0) - (b.lastPlayedAt || 0);
|
||||
return `${a.source}:${a.songId}`.localeCompare(`${b.source}:${b.songId}`);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user