diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2023-11-24 11:49:41 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-24 03:49:41 +0000 |
commit | df1e7d0067bb39913eb681ccc920649884fb1938 (patch) | |
tree | 2419feab5c28658adb7f71878df646bdc9bdc50e /routers/web/shared | |
parent | d24a8223ce1e47a0c9b103aae07f67c3112ca048 (diff) | |
download | gitea-df1e7d0067bb39913eb681ccc920649884fb1938.tar.gz gitea-df1e7d0067bb39913eb681ccc920649884fb1938.zip |
Use db.Find instead of writing methods for every object (#28084)
For those simple objects, it's unnecessary to write the find and count
methods again and again.
Diffstat (limited to 'routers/web/shared')
-rw-r--r-- | routers/web/shared/actions/runners.go | 18 | ||||
-rw-r--r-- | routers/web/shared/actions/variables.go | 2 | ||||
-rw-r--r-- | routers/web/shared/secrets/secrets.go | 3 | ||||
-rw-r--r-- | routers/web/shared/user/header.go | 4 |
4 files changed, 9 insertions, 18 deletions
diff --git a/routers/web/shared/actions/runners.go b/routers/web/shared/actions/runners.go index 1da4ddf14f..ae9a376724 100644 --- a/routers/web/shared/actions/runners.go +++ b/routers/web/shared/actions/runners.go @@ -17,18 +17,13 @@ import ( // RunnersList prepares data for runners list func RunnersList(ctx *context.Context, opts actions_model.FindRunnerOptions) { - count, err := actions_model.CountRunners(ctx, opts) + runners, count, err := db.FindAndCount[actions_model.ActionRunner](ctx, opts) if err != nil { ctx.ServerError("CountRunners", err) return } - runners, err := actions_model.FindRunners(ctx, opts) - if err != nil { - ctx.ServerError("FindRunners", err) - return - } - if err := runners.LoadAttributes(ctx); err != nil { + if err := actions_model.RunnerList(runners).LoadAttributes(ctx); err != nil { ctx.ServerError("LoadAttributes", err) return } @@ -89,18 +84,13 @@ func RunnerDetails(ctx *context.Context, page int, runnerID, ownerID, repoID int RunnerID: runner.ID, } - count, err := actions_model.CountTasks(ctx, opts) + tasks, count, err := db.FindAndCount[actions_model.ActionTask](ctx, opts) if err != nil { ctx.ServerError("CountTasks", err) return } - tasks, err := actions_model.FindTasks(ctx, opts) - if err != nil { - ctx.ServerError("FindTasks", err) - return - } - if err = tasks.LoadAttributes(ctx); err != nil { + if err = actions_model.TaskList(tasks).LoadAttributes(ctx); err != nil { ctx.ServerError("TasksLoadAttributes", err) return } diff --git a/routers/web/shared/actions/variables.go b/routers/web/shared/actions/variables.go index 341c18f589..07a0575207 100644 --- a/routers/web/shared/actions/variables.go +++ b/routers/web/shared/actions/variables.go @@ -18,7 +18,7 @@ import ( ) func SetVariablesContext(ctx *context.Context, ownerID, repoID int64) { - variables, err := actions_model.FindVariables(ctx, actions_model.FindVariablesOpts{ + variables, err := db.Find[actions_model.ActionVariable](ctx, actions_model.FindVariablesOpts{ OwnerID: ownerID, RepoID: repoID, }) diff --git a/routers/web/shared/secrets/secrets.go b/routers/web/shared/secrets/secrets.go index 875cb0cfec..c805da734a 100644 --- a/routers/web/shared/secrets/secrets.go +++ b/routers/web/shared/secrets/secrets.go @@ -4,6 +4,7 @@ package secrets import ( + "code.gitea.io/gitea/models/db" secret_model "code.gitea.io/gitea/models/secret" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/log" @@ -14,7 +15,7 @@ import ( ) func SetSecretsContext(ctx *context.Context, ownerID, repoID int64) { - secrets, err := secret_model.FindSecrets(ctx, secret_model.FindSecretsOptions{OwnerID: ownerID, RepoID: repoID}) + secrets, err := db.Find[secret_model.Secret](ctx, secret_model.FindSecretsOptions{OwnerID: ownerID, RepoID: repoID}) if err != nil { ctx.ServerError("FindSecrets", err) return diff --git a/routers/web/shared/user/header.go b/routers/web/shared/user/header.go index 998a0c896b..411d499eb4 100644 --- a/routers/web/shared/user/header.go +++ b/routers/web/shared/user/header.go @@ -60,7 +60,7 @@ func PrepareContextForProfileBigAvatar(ctx *context.Context) { } showPrivate := ctx.IsSigned && (ctx.Doer.IsAdmin || ctx.Doer.ID == ctx.ContextUser.ID) - orgs, err := organization.FindOrgs(ctx, organization.FindOrgOptions{ + orgs, err := db.Find[organization.Organization](ctx, organization.FindOrgOptions{ UserID: ctx.ContextUser.ID, IncludePrivate: showPrivate, }) @@ -141,7 +141,7 @@ func LoadHeaderCount(ctx *context.Context) error { } else { projectType = project_model.TypeIndividual } - projectCount, err := project_model.CountProjects(ctx, project_model.SearchOptions{ + projectCount, err := db.Count[project_model.Project](ctx, project_model.SearchOptions{ OwnerID: ctx.ContextUser.ID, IsClosed: util.OptionalBoolOf(false), Type: projectType, |