mirror of
https://git.vectorsigma.ru/public/photoview.git
synced 2026-08-03 21:09:05 +00:00
Fix bug where DetectFaces would be called with the wrong media.
This happend because the go routine did not capture the media variable, and so the it would change before the go routine could start and call the DetectFaces function.
This commit is contained in:
@@ -321,7 +321,7 @@ func (r *mutationResolver) UserRemoveRootAlbum(ctx context.Context, userID int,
|
||||
|
||||
var deletedAlbumIDs []int = nil
|
||||
|
||||
err := r.Database.Transaction(func(tx *gorm.DB) error {
|
||||
transactionError := r.Database.Transaction(func(tx *gorm.DB) error {
|
||||
if err := tx.Raw("DELETE FROM user_albums WHERE user_id = ? AND album_id = ?", userID, albumID).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -346,12 +346,12 @@ func (r *mutationResolver) UserRemoveRootAlbum(ctx context.Context, userID int,
|
||||
}
|
||||
|
||||
// Cleanup if no user owns the album anymore
|
||||
var count int
|
||||
if err := tx.Raw("SELECT COUNT(user_id) FROM user_albums WHERE album_id = ?", albumID).Scan(&count).Error; err != nil {
|
||||
var userAlbumCount int
|
||||
if err := tx.Raw("SELECT COUNT(user_id) FROM user_albums WHERE album_id = ?", albumID).Scan(&userAlbumCount).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if count == 0 {
|
||||
if userAlbumCount == 0 {
|
||||
deletedAlbumIDs = append(childAlbumIDs, albumID)
|
||||
childAlbumIDs = nil
|
||||
|
||||
@@ -360,17 +360,13 @@ func (r *mutationResolver) UserRemoveRootAlbum(ctx context.Context, userID int,
|
||||
deletedAlbumIDs = nil
|
||||
return err
|
||||
}
|
||||
|
||||
if err := face_detection.GlobalFaceDetector.ReloadFacesFromDatabase(tx); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
if transactionError != nil {
|
||||
return nil, transactionError
|
||||
}
|
||||
|
||||
if deletedAlbumIDs != nil {
|
||||
@@ -382,6 +378,11 @@ func (r *mutationResolver) UserRemoveRootAlbum(ctx context.Context, userID int,
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
// Reload faces as media might have been deleted
|
||||
if err := face_detection.GlobalFaceDetector.ReloadFacesFromDatabase(r.Database); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return &album, nil
|
||||
|
||||
Reference in New Issue
Block a user