mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 18:28:37 +00:00
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.
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
@@ -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,
|
||||
})
|
||||
|
@@ -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
|
||||
|
@@ -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,
|
||||
|
Reference in New Issue
Block a user