aboutsummaryrefslogtreecommitdiffstats
path: root/models/db/context.go
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2025-03-04 10:25:20 -0800
committerGitHub <noreply@github.com>2025-03-04 18:25:20 +0000
commit6c8fb8d455cfe25d5aa966674624bce99fba1735 (patch)
treefdc466b99aa508a8738960200d2f0a1bbaf0b620 /models/db/context.go
parent75e85c25c1674627ef750bf7114d3b0b7c0d15aa (diff)
downloadgitea-6c8fb8d455cfe25d5aa966674624bce99fba1735.tar.gz
gitea-6c8fb8d455cfe25d5aa966674624bce99fba1735.zip
Small refactor to reduce unnecessary database queries and remove duplicated functions (#33779)
Diffstat (limited to 'models/db/context.go')
-rw-r--r--models/db/context.go3
1 files changed, 3 insertions, 0 deletions
diff --git a/models/db/context.go b/models/db/context.go
index 51627712b1..4b98796ef0 100644
--- a/models/db/context.go
+++ b/models/db/context.go
@@ -289,6 +289,9 @@ func FindIDs(ctx context.Context, tableName, idCol string, cond builder.Cond) ([
// DecrByIDs decreases the given column for entities of the "bean" type with one of the given ids by one
// Timestamps of the entities won't be updated
func DecrByIDs(ctx context.Context, ids []int64, decrCol string, bean any) error {
+ if len(ids) == 0 {
+ return nil
+ }
_, err := GetEngine(ctx).Decr(decrCol).In("id", ids).NoAutoCondition().NoAutoTime().Update(bean)
return err
}