Skip to content

Commit 484b334

Browse files
committed
improve
1 parent 4175d64 commit 484b334

File tree

2 files changed

+17
-20
lines changed

2 files changed

+17
-20
lines changed

models/git/branch.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -463,16 +463,22 @@ func FindRecentlyPushedNewBranches(ctx context.Context, doer *user_model.User, o
463463
}
464464

465465
// find all related branches, these branches may already created PRs, we will check later
466-
branches, err := db.Find[Branch](ctx, FindBranchOptions{
467-
RepoCond: builder.In("branch.repo_id", repoIDs),
468-
CommitCond: builder.Neq{"branch.commit_id": baseBranch.CommitID}, // newly created branch have no changes, so skip them,
466+
var branches []*Branch
467+
cond := FindBranchOptions{
469468
PusherID: doer.ID,
470469
IsDeletedBranch: optional.Some(false),
471470
CommitAfterUnix: opts.CommitAfterUnix,
472-
OrderBy: "branch.updated_unix DESC",
473471
ListOptions: db.ListOptionsAll,
474-
})
475-
if err != nil {
472+
}.ToConds()
473+
cond = cond.And(
474+
builder.In("repo_id", repoIDs),
475+
// newly created branch have no changes, so skip them
476+
builder.Neq{"commit_id": baseBranch.CommitID},
477+
)
478+
if err := db.GetEngine(ctx).
479+
Where(cond).
480+
OrderBy(db.SearchOrderByRecentUpdated.String()).
481+
Find(&branches); err != nil {
476482
return nil, err
477483
}
478484

models/git/branch_list.go

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,7 @@ func (branches BranchList) LoadRepo(ctx context.Context) error {
8181
type FindBranchOptions struct {
8282
db.ListOptions
8383
RepoID int64
84-
RepoCond builder.Cond
8584
ExcludeBranchNames []string
86-
CommitCond builder.Cond
8785
PusherID int64
8886
IsDeletedBranch optional.Option[bool]
8987
CommitAfterUnix int64
@@ -98,34 +96,27 @@ func (opts FindBranchOptions) ToConds() builder.Cond {
9896
if opts.RepoID > 0 {
9997
cond = cond.And(builder.Eq{"repo_id": opts.RepoID})
10098
}
101-
if opts.RepoCond != nil {
102-
cond = cond.And(opts.RepoCond)
103-
}
10499

105100
if len(opts.ExcludeBranchNames) > 0 {
106-
cond = cond.And(builder.NotIn("branch.name", opts.ExcludeBranchNames))
107-
}
108-
109-
if opts.CommitCond != nil {
110-
cond = cond.And(opts.CommitCond)
101+
cond = cond.And(builder.NotIn("name", opts.ExcludeBranchNames))
111102
}
112103

113104
if opts.PusherID > 0 {
114-
cond = cond.And(builder.Eq{"branch.pusher_id": opts.PusherID})
105+
cond = cond.And(builder.Eq{"pusher_id": opts.PusherID})
115106
}
116107

117108
if opts.IsDeletedBranch.Has() {
118-
cond = cond.And(builder.Eq{"branch.is_deleted": opts.IsDeletedBranch.Value()})
109+
cond = cond.And(builder.Eq{"is_deleted": opts.IsDeletedBranch.Value()})
119110
}
120111
if opts.Keyword != "" {
121112
cond = cond.And(builder.Like{"name", opts.Keyword})
122113
}
123114

124115
if opts.CommitAfterUnix != 0 {
125-
cond = cond.And(builder.Gte{"branch.commit_time": opts.CommitAfterUnix})
116+
cond = cond.And(builder.Gte{"commit_time": opts.CommitAfterUnix})
126117
}
127118
if opts.CommitBeforeUnix != 0 {
128-
cond = cond.And(builder.Lte{"branch.commit_time": opts.CommitBeforeUnix})
119+
cond = cond.And(builder.Lte{"commit_time": opts.CommitBeforeUnix})
129120
}
130121

131122
return cond

0 commit comments

Comments
 (0)