loading up the forgejo repo on tangled to test page performance
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge pull request '[BUG] Load `AllUnitsEnabled` when necessary' (#2420) from gusted/forgejo-add-more into forgejo

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/2420
Reviewed-by: Otto <otto@codeberg.org>
Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org>

+26 -27
+25
models/repo/repo.go
··· 439 439 return nil, ErrUnitTypeNotExist{tp} 440 440 } 441 441 442 + // AllUnitsEnabled returns true if all units are enabled for the repo. 443 + func (repo *Repository) AllUnitsEnabled(ctx context.Context) bool { 444 + hasAnyUnitEnabled := func(unitGroup []unit.Type) bool { 445 + // Loop over the group of units 446 + for _, unit := range unitGroup { 447 + // If *any* of them is enabled, return true. 448 + if repo.UnitEnabled(ctx, unit) { 449 + return true 450 + } 451 + } 452 + 453 + // If none are enabled, return false. 454 + return false 455 + } 456 + 457 + for _, unitGroup := range unit.AllowedRepoUnitGroups { 458 + // If any disabled unit is found, return false immediately. 459 + if !hasAnyUnitEnabled(unitGroup) { 460 + return false 461 + } 462 + } 463 + 464 + return true 465 + } 466 + 442 467 // LoadOwner loads owner user 443 468 func (repo *Repository) LoadOwner(ctx context.Context) (err error) { 444 469 if repo.Owner != nil {
-26
modules/context/repo.go
··· 82 82 return r.Permission.CanWrite(unit_model.TypeCode) && r.Repository.CanCreateBranch() 83 83 } 84 84 85 - // AllUnitsEnabled returns true if all units are enabled for the repo. 86 - func (r *Repository) AllUnitsEnabled(ctx context.Context) bool { 87 - hasAnyUnitEnabled := func(unitGroup []unit_model.Type) bool { 88 - // Loop over the group of units 89 - for _, unit := range unitGroup { 90 - // If *any* of them is enabled, return true. 91 - if r.Repository.UnitEnabled(ctx, unit) { 92 - return true 93 - } 94 - } 95 - 96 - // If none are enabled, return false. 97 - return false 98 - } 99 - 100 - for _, unitGroup := range unit_model.AllowedRepoUnitGroups { 101 - // If any disabled unit is found, return false immediately. 102 - if !hasAnyUnitEnabled(unitGroup) { 103 - return false 104 - } 105 - } 106 - 107 - return true 108 - } 109 - 110 85 // RepoMustNotBeArchived checks if a repo is archived 111 86 func RepoMustNotBeArchived() func(ctx *Context) { 112 87 return func(ctx *Context) { ··· 1079 1054 ctx.Data["IsViewTag"] = ctx.Repo.IsViewTag 1080 1055 ctx.Data["IsViewCommit"] = ctx.Repo.IsViewCommit 1081 1056 ctx.Data["CanCreateBranch"] = ctx.Repo.CanCreateBranch() 1082 - ctx.Data["AllUnitsEnabled"] = ctx.Repo.AllUnitsEnabled(ctx) 1083 1057 1084 1058 ctx.Repo.CommitsCount, err = ctx.Repo.GetCommitsCount() 1085 1059 if err != nil {
+1 -1
templates/repo/header.tmpl
··· 219 219 {{end}} 220 220 221 221 {{if .Permission.IsAdmin}} 222 - {{if not .AllUnitsEnabled}} 222 + {{if not (.Repository.AllUnitsEnabled ctx)}} 223 223 <a class="{{if .PageIsRepoSettingsUnits}}active {{end}}item" href="{{.RepoLink}}/settings/units"> 224 224 {{svg "octicon-diff-added"}} {{ctx.Locale.Tr "repo.settings.units.add_more"}} 225 225 </a>