bug处理

This commit is contained in:
truewhile
2026-09-14 21:40:13 +08:00
parent 1ec8303fec
commit fa4c90d47a
7 changed files with 94 additions and 5 deletions
+4 -2
View File
@@ -70,7 +70,9 @@ func SortSeriesCards(cards []SeriesCard, field, order string, history map[string
}
sort.SliceStable(out, func(i, j int) bool {
cmp := compareSeriesByField(out[i], out[j], spec, history)
if cmp == 0 {
// updated_at 表示最后一集添加日期。远程卡片可能没有该字段,此时
// 保持调用方给定的顺序,不要用 ID 再次打乱。
if cmp == 0 && spec.Field != "updated_at" {
cmp = compareID(out[i].Key, out[j].Key)
}
return cmp < 0
@@ -173,7 +175,7 @@ func seriesUpdatedTime(card SeriesCard) (time.Time, bool) {
if card.LastAddedAt != nil && !card.LastAddedAt.IsZero() {
return *card.LastAddedAt, true
}
return mediaUpdatedTime(card.Rep)
return time.Time{}, false
}
func seriesLastPlayed(card SeriesCard, history map[string]time.Time) (time.Time, bool) {
+43
View File
@@ -2,6 +2,7 @@ package service
import (
"testing"
"time"
"github.com/truewhile/MeBox/internal/model"
)
@@ -40,3 +41,45 @@ func TestSortSeriesCardsTitleAsc(t *testing.T) {
t.Fatalf("series order = %q, %q", got[0].Key, got[1].Key)
}
}
func TestSortSeriesCardsUpdatedAtDoesNotFallbackToMediaDate(t *testing.T) {
olderMediaDate := time.Date(2023, time.January, 1, 0, 0, 0, 0, time.UTC)
newerMediaDate := time.Date(2025, time.January, 1, 0, 0, 0, 0, time.UTC)
cards := []SeriesCard{
{
Key: "remote-first",
Rep: model.Media{Base: model.Base{
ID: "remote-first",
CreatedAt: olderMediaDate,
UpdatedAt: olderMediaDate,
}},
},
{
Key: "remote-second",
Rep: model.Media{Base: model.Base{
ID: "remote-second",
CreatedAt: newerMediaDate,
UpdatedAt: newerMediaDate,
}},
},
}
got := SortSeriesCards(cards, "updated_at", "desc", nil)
if got[0].Key != "remote-first" || got[1].Key != "remote-second" {
t.Fatalf("series order = %q, %q, want remote-provided order", got[0].Key, got[1].Key)
}
}
func TestSortSeriesCardsUpdatedAtSortsKnownLastEpisodeDates(t *testing.T) {
older := time.Date(2024, time.January, 1, 0, 0, 0, 0, time.UTC)
newer := time.Date(2025, time.January, 1, 0, 0, 0, 0, time.UTC)
cards := []SeriesCard{
{Key: "older", LastAddedAt: &older},
{Key: "newer", LastAddedAt: &newer},
}
got := SortSeriesCards(cards, "updated_at", "desc", nil)
if got[0].Key != "newer" || got[1].Key != "older" {
t.Fatalf("series order = %q, %q", got[0].Key, got[1].Key)
}
}