Skip to content

Commit 8cea058

Browse files
committed
improve
1 parent 9fcb6b7 commit 8cea058

File tree

2 files changed

+10
-27
lines changed

2 files changed

+10
-27
lines changed

models/git/branch.go

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -464,18 +464,17 @@ func FindRecentlyPushedNewBranches(ctx context.Context, doer *user_model.User, o
464464

465465
// find all related branches, these branches may already created PRs, we will check later
466466
var branches []*Branch
467-
cond := FindBranchOptions{
468-
PusherID: doer.ID,
469-
IsDeletedBranch: optional.Some(false),
470-
CommitAfterUnix: opts.CommitAfterUnix,
471-
}.ToConds()
472-
cond = cond.And(
473-
builder.In("repo_id", repoIDs),
474-
// newly created branch have no changes, so skip them
475-
builder.Neq{"commit_id": baseBranch.CommitID},
476-
)
477467
if err := db.GetEngine(ctx).
478-
Where(cond).
468+
Where(builder.And(
469+
builder.Eq{
470+
"pusher_id": doer.ID,
471+
"is_deleted": false,
472+
},
473+
builder.Gte{"commit_time": opts.CommitAfterUnix},
474+
builder.In("repo_id", repoIDs),
475+
// newly created branch have no changes, so skip them
476+
builder.Neq{"commit_id": baseBranch.CommitID},
477+
)).
479478
OrderBy(db.SearchOrderByRecentUpdated.String()).
480479
Find(&branches); err != nil {
481480
return nil, err

models/git/branch_list.go

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -84,41 +84,25 @@ type FindBranchOptions struct {
8484
ExcludeBranchNames []string
8585
PusherID int64
8686
IsDeletedBranch optional.Option[bool]
87-
CommitAfterUnix int64
88-
CommitBeforeUnix int64
8987
OrderBy string
9088
Keyword string
9189
}
9290

9391
func (opts FindBranchOptions) ToConds() builder.Cond {
9492
cond := builder.NewCond()
95-
9693
if opts.RepoID > 0 {
9794
cond = cond.And(builder.Eq{"repo_id": opts.RepoID})
9895
}
9996

10097
if len(opts.ExcludeBranchNames) > 0 {
10198
cond = cond.And(builder.NotIn("name", opts.ExcludeBranchNames))
10299
}
103-
104-
if opts.PusherID > 0 {
105-
cond = cond.And(builder.Eq{"pusher_id": opts.PusherID})
106-
}
107-
108100
if opts.IsDeletedBranch.Has() {
109101
cond = cond.And(builder.Eq{"is_deleted": opts.IsDeletedBranch.Value()})
110102
}
111103
if opts.Keyword != "" {
112104
cond = cond.And(builder.Like{"name", opts.Keyword})
113105
}
114-
115-
if opts.CommitAfterUnix != 0 {
116-
cond = cond.And(builder.Gte{"commit_time": opts.CommitAfterUnix})
117-
}
118-
if opts.CommitBeforeUnix != 0 {
119-
cond = cond.And(builder.Lte{"commit_time": opts.CommitBeforeUnix})
120-
}
121-
122106
return cond
123107
}
124108

0 commit comments

Comments
 (0)