Skip to content

Commit

Permalink
improve
Browse files Browse the repository at this point in the history
  • Loading branch information
yp05327 committed May 21, 2024
1 parent 9fcb6b7 commit 59b9311
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 26 deletions.
21 changes: 10 additions & 11 deletions models/git/branch.go
Original file line number Diff line number Diff line change
Expand Up @@ -464,18 +464,17 @@ func FindRecentlyPushedNewBranches(ctx context.Context, doer *user_model.User, o

// find all related branches, these branches may already created PRs, we will check later
var branches []*Branch
cond := FindBranchOptions{
PusherID: doer.ID,
IsDeletedBranch: optional.Some(false),
CommitAfterUnix: opts.CommitAfterUnix,
}.ToConds()
cond = cond.And(
builder.In("repo_id", repoIDs),
// newly created branch have no changes, so skip them
builder.Neq{"commit_id": baseBranch.CommitID},
)
if err := db.GetEngine(ctx).
Where(cond).
Where(builder.And(
builder.Eq{
"pusher_id": doer.ID,
"is_deleted": false,
},
builder.Gte{"commit_time": opts.CommitAfterUnix},
builder.In("repo_id", repoIDs),
// newly created branch have no changes, so skip them
builder.Neq{"commit_id": baseBranch.CommitID},
)).
OrderBy(db.SearchOrderByRecentUpdated.String()).
Find(&branches); err != nil {
return nil, err
Expand Down
15 changes: 0 additions & 15 deletions models/git/branch_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,6 @@ type FindBranchOptions struct {
ExcludeBranchNames []string
PusherID int64
IsDeletedBranch optional.Option[bool]
CommitAfterUnix int64
CommitBeforeUnix int64
OrderBy string
Keyword string
}
Expand All @@ -100,25 +98,12 @@ func (opts FindBranchOptions) ToConds() builder.Cond {
if len(opts.ExcludeBranchNames) > 0 {
cond = cond.And(builder.NotIn("name", opts.ExcludeBranchNames))
}

if opts.PusherID > 0 {
cond = cond.And(builder.Eq{"pusher_id": opts.PusherID})
}

if opts.IsDeletedBranch.Has() {
cond = cond.And(builder.Eq{"is_deleted": opts.IsDeletedBranch.Value()})
}
if opts.Keyword != "" {
cond = cond.And(builder.Like{"name", opts.Keyword})
}

if opts.CommitAfterUnix != 0 {
cond = cond.And(builder.Gte{"commit_time": opts.CommitAfterUnix})
}
if opts.CommitBeforeUnix != 0 {
cond = cond.And(builder.Lte{"commit_time": opts.CommitBeforeUnix})
}

return cond
}

Expand Down

0 comments on commit 59b9311

Please sign in to comment.