1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-22 10:18:38 +00:00

Move db related basic functions to models/db (#17075)

* Move db related basic functions to models/db

* Fix lint

* Fix lint

* Fix test

* Fix lint

* Fix lint

* revert unnecessary change

* Fix test

* Fix wrong replace string

* Use *Context

* Correct committer spelling and fix wrong replaced words

Co-authored-by: zeripath <art27@cantab.net>
This commit is contained in:
Lunny Xiao
2021-09-19 19:49:59 +08:00
committed by GitHub
parent 462306e263
commit a4bfef265d
335 changed files with 4191 additions and 3654 deletions

View File

@@ -4,6 +4,8 @@
package models
import "code.gitea.io/gitea/models/db"
// CommentList defines a list of comments
type CommentList []*Comment
@@ -17,7 +19,7 @@ func (comments CommentList) getPosterIDs() []int64 {
return keysInt64(posterIDs)
}
func (comments CommentList) loadPosters(e Engine) error {
func (comments CommentList) loadPosters(e db.Engine) error {
if len(comments) == 0 {
return nil
}
@@ -70,7 +72,7 @@ func (comments CommentList) getLabelIDs() []int64 {
return keysInt64(ids)
}
func (comments CommentList) loadLabels(e Engine) error {
func (comments CommentList) loadLabels(e db.Engine) error {
if len(comments) == 0 {
return nil
}
@@ -120,7 +122,7 @@ func (comments CommentList) getMilestoneIDs() []int64 {
return keysInt64(ids)
}
func (comments CommentList) loadMilestones(e Engine) error {
func (comments CommentList) loadMilestones(e db.Engine) error {
if len(comments) == 0 {
return nil
}
@@ -163,7 +165,7 @@ func (comments CommentList) getOldMilestoneIDs() []int64 {
return keysInt64(ids)
}
func (comments CommentList) loadOldMilestones(e Engine) error {
func (comments CommentList) loadOldMilestones(e db.Engine) error {
if len(comments) == 0 {
return nil
}
@@ -206,7 +208,7 @@ func (comments CommentList) getAssigneeIDs() []int64 {
return keysInt64(ids)
}
func (comments CommentList) loadAssignees(e Engine) error {
func (comments CommentList) loadAssignees(e db.Engine) error {
if len(comments) == 0 {
return nil
}
@@ -280,7 +282,7 @@ func (comments CommentList) Issues() IssueList {
return issueList
}
func (comments CommentList) loadIssues(e Engine) error {
func (comments CommentList) loadIssues(e db.Engine) error {
if len(comments) == 0 {
return nil
}
@@ -337,7 +339,7 @@ func (comments CommentList) getDependentIssueIDs() []int64 {
return keysInt64(ids)
}
func (comments CommentList) loadDependentIssues(e Engine) error {
func (comments CommentList) loadDependentIssues(e db.Engine) error {
if len(comments) == 0 {
return nil
}
@@ -386,7 +388,7 @@ func (comments CommentList) loadDependentIssues(e Engine) error {
return nil
}
func (comments CommentList) loadAttachments(e Engine) (err error) {
func (comments CommentList) loadAttachments(e db.Engine) (err error) {
if len(comments) == 0 {
return nil
}
@@ -438,7 +440,7 @@ func (comments CommentList) getReviewIDs() []int64 {
return keysInt64(ids)
}
func (comments CommentList) loadReviews(e Engine) error {
func (comments CommentList) loadReviews(e db.Engine) error {
if len(comments) == 0 {
return nil
}
@@ -481,7 +483,7 @@ func (comments CommentList) loadReviews(e Engine) error {
}
// loadAttributes loads all attributes
func (comments CommentList) loadAttributes(e Engine) (err error) {
func (comments CommentList) loadAttributes(e db.Engine) (err error) {
if err = comments.loadPosters(e); err != nil {
return
}
@@ -524,20 +526,20 @@ func (comments CommentList) loadAttributes(e Engine) (err error) {
// LoadAttributes loads attributes of the comments, except for attachments and
// comments
func (comments CommentList) LoadAttributes() error {
return comments.loadAttributes(x)
return comments.loadAttributes(db.DefaultContext().Engine())
}
// LoadAttachments loads attachments
func (comments CommentList) LoadAttachments() error {
return comments.loadAttachments(x)
return comments.loadAttachments(db.DefaultContext().Engine())
}
// LoadPosters loads posters
func (comments CommentList) LoadPosters() error {
return comments.loadPosters(x)
return comments.loadPosters(db.DefaultContext().Engine())
}
// LoadIssues loads issues of comments
func (comments CommentList) LoadIssues() error {
return comments.loadIssues(x)
return comments.loadIssues(db.DefaultContext().Engine())
}