Navigation: Update counts when saving a photo #996

This commit is contained in:
Michael Mayer 2021-02-05 18:22:52 +01:00
parent f6b5a32895
commit 63ba28426e
3 changed files with 9 additions and 13 deletions

View file

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

View file

@ -113,6 +113,8 @@ func UpdatePhoto(router *gin.RouterGroup) {
SavePhotoAsYaml(p)
UpdateClientConfig()
c.JSON(http.StatusOK, p)
})
}

View file

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