mirror of
https://github.com/truewhile/MeBox.git
synced 2026-09-28 03:06:38 +08:00
处理删库重建库没有媒体数据bug
本地文件入库媒体库删除后重新入库导致0条目bug
This commit is contained in:
@@ -51,6 +51,13 @@ func TestDeleteLibraryHardDeletesLibraryRoots(t *testing.T) {
|
||||
if visibleLibraryCount != 0 {
|
||||
t.Fatalf("deleted library should not remain visible, count=%d", visibleLibraryCount)
|
||||
}
|
||||
var mediaCount int64
|
||||
if err := db.Unscoped().Model(&model.Media{}).Where("library_id = ?", lib.ID).Count(&mediaCount).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if mediaCount != 0 {
|
||||
t.Fatalf("local library media rows should be hard deleted, count=%d", mediaCount)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDeleteCloudLibraryPurgesMountWithoutRecycleBin(t *testing.T) {
|
||||
|
||||
@@ -37,7 +37,10 @@ func (s *MediaService) DeleteLibrary(ctx context.Context, id string) error {
|
||||
}
|
||||
}
|
||||
err = s.repo.DB.WithContext(ctx).Transaction(func(tx *gorm.DB) error {
|
||||
if err := tx.Where("library_id = ?", id).Delete(&model.Media{}).Error; err != nil {
|
||||
// 本地库媒体行统一硬删除(与云库分支一致):删库即彻底清空该库的
|
||||
// media 行,避免重扫时旧行被 upsert 复活却仍挂在已删库下,导致重建
|
||||
// 同名库后条目始终为 0。只作用于数据库表行,磁盘文件不受影响。
|
||||
if err := tx.Unscoped().Where("library_id = ?", id).Delete(&model.Media{}).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if err := hardDeleteLibraryRoots(ctx, tx, id); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user