From 92f139d091c906cc6d30599101d45c62a208f585 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Tue, 3 May 2022 21:46:28 +0200 Subject: Use for a repo action one database transaction (#19576) ... more context (part of #9307) --- models/repo/repo.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'models/repo') diff --git a/models/repo/repo.go b/models/repo/repo.go index fc72d36dac..8af6357bf3 100644 --- a/models/repo/repo.go +++ b/models/repo/repo.go @@ -302,8 +302,19 @@ func (repo *Repository) LoadUnits(ctx context.Context) (err error) { } // UnitEnabled if this repository has the given unit enabled -func (repo *Repository) UnitEnabled(tp unit.Type) bool { - if err := repo.LoadUnits(db.DefaultContext); err != nil { +func (repo *Repository) UnitEnabled(tp unit.Type) (result bool) { + if err := db.WithContext(func(ctx *db.Context) error { + result = repo.UnitEnabledCtx(ctx, tp) + return nil + }); err != nil { + log.Error("repo.UnitEnabled: %v", err) + } + return +} + +// UnitEnabled if this repository has the given unit enabled +func (repo *Repository) UnitEnabledCtx(ctx context.Context, tp unit.Type) bool { + if err := repo.LoadUnits(ctx); err != nil { log.Warn("Error loading repository (ID: %d) units: %s", repo.ID, err.Error()) } for _, unit := range repo.Units { -- cgit v1.2.3