diff --git a/internal/api/batch.go b/internal/api/batch.go index b403cb937..2ed355959 100644 --- a/internal/api/batch.go +++ b/internal/api/batch.go @@ -63,9 +63,7 @@ func BatchPhotosArchive(router *gin.RouterGroup) { log.Errorf("archive: %s", err) } - if err := entity.UpdatePhotoCounts(); err != nil { - log.Errorf("photos: %s", err) - } + logError("photos", entity.UpdatePhotoCounts()) UpdateClientConfig() @@ -121,9 +119,7 @@ func BatchPhotosRestore(router *gin.RouterGroup) { return } - if err := entity.UpdatePhotoCounts(); err != nil { - log.Errorf("photos: %s", err) - } + logError("photos", entity.UpdatePhotoCounts()) UpdateClientConfig() @@ -249,9 +245,7 @@ func BatchPhotosPrivate(router *gin.RouterGroup) { return } - if err := entity.UpdatePhotoCounts(); err != nil { - log.Errorf("photos: %s", err) - } + logError("photos", entity.UpdatePhotoCounts()) if photos, err := query.PhotoSelection(f); err == nil { for _, p := range photos { @@ -364,9 +358,7 @@ func BatchPhotosDelete(router *gin.RouterGroup) { // Update counts and views if needed. if len(deleted) > 0 { - if err := entity.UpdatePhotoCounts(); err != nil { - log.Errorf("photos: %s", err) - } + logError("photos", entity.UpdatePhotoCounts()) UpdateClientConfig() diff --git a/internal/api/photo.go b/internal/api/photo.go index c42384064..7c514f157 100644 --- a/internal/api/photo.go +++ b/internal/api/photo.go @@ -113,6 +113,8 @@ func UpdatePhoto(router *gin.RouterGroup) { SavePhotoAsYaml(p) + UpdateClientConfig() + c.JSON(http.StatusOK, p) }) } diff --git a/internal/entity/save.go b/internal/entity/save.go index 9c26cf67d..98c037c53 100644 --- a/internal/entity/save.go +++ b/internal/entity/save.go @@ -37,13 +37,15 @@ func Update(m interface{}, primaryKeys ...string) (err error) { v := reflect.ValueOf(m).Elem() + // Abort if a primary key is zero. for _, k := range primaryKeys { if field := v.FieldByName(k); field.IsZero() { return fmt.Errorf("key '%s' not found", k) } } - if res := UnscopedDb().Model(m).Omit(primaryKeys...).Updates(m); res.Error != nil { + // Update all values except primary keys. + if res := UnscopedDb().Model(m).Select("*").Omit(primaryKeys...).Updates(m); res.Error != nil { return res.Error } else if res.RowsAffected == 0 { return fmt.Errorf("no entity found for updating")