mirror of
https://github.com/photoprism/photoprism.git
synced 2026-07-19 17:46:11 +00:00
Run `go fix ./...` and keep mechanical modernization updates.
- Replace `interface{}` with `any` in signatures and local types
- Apply formatter/style cleanups from go1.26 tooling
- Keep `omitempty` behavior-preserving simplifications suggested by fix
- No functional feature changes intended
Validation:
- go test ./... -run '^$' -count=1 (Go 1.26.0)
- GOTOOLCHAIN=go1.24.10 go test ./... -run '^$' -count=1
Signed-off-by: Michael Mayer <michael@photoprism.app>
34 lines
736 B
Go
34 lines
736 B
Go
package entity
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
)
|
|
|
|
// Save tries to update an existing record and falls back to insert semantics, retrying on lock errors.
|
|
func Save(m any, keyNames ...string) (err error) {
|
|
defer func() {
|
|
if r := recover(); r != nil {
|
|
err = fmt.Errorf("save: %s (panic)", r)
|
|
}
|
|
}()
|
|
|
|
// Try a regular update first.
|
|
if err = Update(m, keyNames...); err == nil {
|
|
return nil
|
|
}
|
|
|
|
// Automatically insert/update record as needed.
|
|
if err = UnscopedDb().Save(m).Error; err == nil {
|
|
return nil
|
|
}
|
|
|
|
// Try again if database was locked, return otherwise.
|
|
if !strings.Contains(strings.ToLower(err.Error()), "lock") {
|
|
return err
|
|
} else if err = UnscopedDb().Save(m).Error; err == nil {
|
|
return nil
|
|
}
|
|
|
|
return err
|
|
}
|