mirror of
https://github.com/go-gitea/gitea
synced 2025-07-03 09:07:19 +00:00
Move more functions to db.Find (#28419)
Following #28220 This PR move more functions to use `db.Find`. --------- Co-authored-by: delvh <dev.lh@web.de>
This commit is contained in:
@ -28,7 +28,6 @@ import (
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
|
||||
"xorm.io/builder"
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
|
||||
// ErrCommentNotExist represents a "CommentNotExist" kind of error.
|
||||
@ -338,7 +337,7 @@ func (c *Comment) BeforeUpdate() {
|
||||
}
|
||||
|
||||
// AfterLoad is invoked from XORM after setting the values of all fields of this object.
|
||||
func (c *Comment) AfterLoad(session *xorm.Session) {
|
||||
func (c *Comment) AfterLoad() {
|
||||
c.Patch = c.PatchQuoted
|
||||
if len(c.PatchQuoted) > 0 && c.PatchQuoted[0] == '"' {
|
||||
unquoted, err := strconv.Unquote(c.PatchQuoted)
|
||||
|
@ -94,7 +94,7 @@ type FindTrackedTimesOptions struct {
|
||||
}
|
||||
|
||||
// toCond will convert each condition into a xorm-Cond
|
||||
func (opts *FindTrackedTimesOptions) toCond() builder.Cond {
|
||||
func (opts *FindTrackedTimesOptions) ToConds() builder.Cond {
|
||||
cond := builder.NewCond().And(builder.Eq{"tracked_time.deleted": false})
|
||||
if opts.IssueID != 0 {
|
||||
cond = cond.And(builder.Eq{"issue_id": opts.IssueID})
|
||||
@ -117,6 +117,18 @@ func (opts *FindTrackedTimesOptions) toCond() builder.Cond {
|
||||
return cond
|
||||
}
|
||||
|
||||
func (opts *FindTrackedTimesOptions) ToJoins() []db.JoinFunc {
|
||||
if opts.RepositoryID > 0 || opts.MilestoneID > 0 {
|
||||
return []db.JoinFunc{
|
||||
func(e db.Engine) error {
|
||||
e.Join("INNER", "issue", "issue.id = tracked_time.issue_id")
|
||||
return nil
|
||||
},
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// toSession will convert the given options to a xorm Session by using the conditions from toCond and joining with issue table if required
|
||||
func (opts *FindTrackedTimesOptions) toSession(e db.Engine) db.Engine {
|
||||
sess := e
|
||||
@ -124,10 +136,10 @@ func (opts *FindTrackedTimesOptions) toSession(e db.Engine) db.Engine {
|
||||
sess = e.Join("INNER", "issue", "issue.id = tracked_time.issue_id")
|
||||
}
|
||||
|
||||
sess = sess.Where(opts.toCond())
|
||||
sess = sess.Where(opts.ToConds())
|
||||
|
||||
if opts.Page != 0 {
|
||||
sess = db.SetEnginePagination(sess, opts)
|
||||
sess = db.SetSessionPagination(sess, opts)
|
||||
}
|
||||
|
||||
return sess
|
||||
@ -141,7 +153,7 @@ func GetTrackedTimes(ctx context.Context, options *FindTrackedTimesOptions) (tra
|
||||
|
||||
// CountTrackedTimes returns count of tracked times that fit to the given options.
|
||||
func CountTrackedTimes(ctx context.Context, opts *FindTrackedTimesOptions) (int64, error) {
|
||||
sess := db.GetEngine(ctx).Where(opts.toCond())
|
||||
sess := db.GetEngine(ctx).Where(opts.ToConds())
|
||||
if opts.RepositoryID > 0 || opts.MilestoneID > 0 {
|
||||
sess = sess.Join("INNER", "issue", "issue.id = tracked_time.issue_id")
|
||||
}
|
||||
|
Reference in New Issue
Block a user