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:
viktorstrate
2021-03-16 22:27:27 +01:00
parent 3ae92086cd
commit a14b12b8d4
3 changed files with 30 additions and 27 deletions

View File

@@ -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