修复关系型数据库保存音乐记录错误,播放记录修改为队列式
This commit is contained in:
+3
-2
@@ -748,7 +748,8 @@ export class D1Storage implements IStorage {
|
||||
async listMusicV2History(userName: string): Promise<MusicV2HistoryRecord[]> {
|
||||
try {
|
||||
const results = await this.db
|
||||
.prepare('SELECT * FROM music_v2_history WHERE username = ? ORDER BY last_played_at DESC')
|
||||
// 按队列顺序返回;当前播放项由最大 last_played_at 决定
|
||||
.prepare('SELECT * FROM music_v2_history WHERE username = ? ORDER BY created_at ASC, last_played_at ASC')
|
||||
.bind(userName)
|
||||
.all();
|
||||
|
||||
@@ -785,7 +786,7 @@ export class D1Storage implements IStorage {
|
||||
username, song_id, source, songmid, name, artist, album, cover, duration_text, duration_sec,
|
||||
play_progress_sec, last_played_at, play_count, last_quality, created_at, updated_at
|
||||
)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
ON CONFLICT(username, song_id) DO UPDATE SET
|
||||
source = excluded.source,
|
||||
songmid = excluded.songmid,
|
||||
|
||||
@@ -273,6 +273,8 @@ export class DbManager {
|
||||
// Music V2 历史记录相关
|
||||
async listMusicV2History(userName: string): Promise<MusicV2HistoryRecord[]> {
|
||||
if (typeof (this.storage as any).listMusicV2History === 'function') {
|
||||
// 按播放队列顺序返回(createdAt ASC),
|
||||
// 当前播放项由调用方基于 lastPlayedAt 决定。
|
||||
return (this.storage as any).listMusicV2History(userName);
|
||||
}
|
||||
return [];
|
||||
|
||||
@@ -1403,7 +1403,8 @@ export class PostgresStorage implements IStorage {
|
||||
async listMusicV2History(userName: string): Promise<MusicV2HistoryRecord[]> {
|
||||
try {
|
||||
const results = await this.db
|
||||
.prepare('SELECT * FROM music_v2_history WHERE username = $1 ORDER BY last_played_at DESC')
|
||||
// 按队列顺序返回;当前播放项由最大 last_played_at 决定
|
||||
.prepare('SELECT * FROM music_v2_history WHERE username = $1 ORDER BY created_at ASC, last_played_at ASC')
|
||||
.bind(userName)
|
||||
.all();
|
||||
|
||||
@@ -1440,7 +1441,7 @@ export class PostgresStorage implements IStorage {
|
||||
username, song_id, source, songmid, name, artist, album, cover, duration_text, duration_sec,
|
||||
play_progress_sec, last_played_at, play_count, last_quality, created_at, updated_at
|
||||
)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16)
|
||||
ON CONFLICT(username, song_id) DO UPDATE SET
|
||||
source = EXCLUDED.source,
|
||||
songmid = EXCLUDED.songmid,
|
||||
|
||||
@@ -807,7 +807,12 @@ export abstract class BaseRedisStorage implements IStorage {
|
||||
return Object.values(rows || {})
|
||||
.filter(Boolean)
|
||||
.map(value => JSON.parse(value as string) as MusicV2HistoryRecord)
|
||||
.sort((a, b) => b.lastPlayedAt - a.lastPlayedAt);
|
||||
// 按队列顺序返回;当前播放项由最大 lastPlayedAt 决定
|
||||
.sort((a, b) => {
|
||||
const createdAtDiff = (a.createdAt || 0) - (b.createdAt || 0);
|
||||
if (createdAtDiff !== 0) return createdAtDiff;
|
||||
return (a.lastPlayedAt || 0) - (b.lastPlayedAt || 0);
|
||||
});
|
||||
}
|
||||
|
||||
async upsertMusicV2History(userName: string, record: MusicV2HistoryRecord): Promise<void> {
|
||||
|
||||
Reference in New Issue
Block a user