mirror of
https://github.com/truewhile/MeBox.git
synced 2026-11-16 12:54:22 +08:00
优化
This commit is contained in:
@@ -237,10 +237,16 @@ func (r *MediaRepository) ListSeasonSiblings(ctx context.Context, m *model.Media
|
||||
} else {
|
||||
libraryID := strings.TrimSpace(m.LibraryID)
|
||||
title := strings.TrimSpace(m.Title)
|
||||
if libraryID == "" || title == "" || m.TMDbID <= 0 {
|
||||
if libraryID == "" || title == "" {
|
||||
return nil, nil
|
||||
}
|
||||
query = query.Where("library_id = ? AND title = ? AND tm_db_id = ?", libraryID, title, m.TMDbID)
|
||||
// 没有 series_id 也没有 TMDb id 时,退到「同库 + 同标题」:手动标记的按季
|
||||
// 传播是用户显式操作,同库同名已经足够可靠;而在缺 id 时直接放弃会让这个
|
||||
// 功能在未刮削的库上完全不生效。
|
||||
query = query.Where("library_id = ? AND title = ?", libraryID, title)
|
||||
if m.TMDbID > 0 {
|
||||
query = query.Where("tm_db_id = ?", m.TMDbID)
|
||||
}
|
||||
}
|
||||
var rows []model.Media
|
||||
if err := query.Find(&rows).Error; err != nil {
|
||||
|
||||
@@ -56,6 +56,23 @@ func (r *MediaSegmentRepository) ReplaceForMedia(ctx context.Context, mediaID, s
|
||||
})
|
||||
}
|
||||
|
||||
// ReplaceForMediaSourceKind swaps the segments of one (media, source, kind)
|
||||
// triple in a single transaction. Used by manual marking, where the user sets
|
||||
// one boundary at a time and must not disturb the other kinds.
|
||||
func (r *MediaSegmentRepository) ReplaceForMediaSourceKind(ctx context.Context, mediaID, source, kind string, rows []model.MediaSegment) error {
|
||||
return r.db.WithContext(ctx).Transaction(func(tx *gorm.DB) error {
|
||||
if err := tx.Unscoped().
|
||||
Where("media_id = ? AND source = ? AND kind = ?", mediaID, source, kind).
|
||||
Delete(&model.MediaSegment{}).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if len(rows) == 0 {
|
||||
return nil
|
||||
}
|
||||
return tx.Create(&rows).Error
|
||||
})
|
||||
}
|
||||
|
||||
// GetFetch returns the fetch ledger row for (media, source), or (nil, nil).
|
||||
func (r *MediaSegmentRepository) GetFetch(ctx context.Context, mediaID, source string) (*model.MediaSegmentFetch, error) {
|
||||
var row model.MediaSegmentFetch
|
||||
|
||||
Reference in New Issue
Block a user