diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2021-11-22 23:21:55 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-22 23:21:55 +0800 |
commit | baed01f24753afb600a2984dcb9bcda0bb8502b6 (patch) | |
tree | 5621ef980b6b0067a21c86be7e4808d83c0538ab /models/star.go | |
parent | c2ab19888f92fbdec4276a16d224e8de80d1d1dd (diff) | |
download | gitea-baed01f24753afb600a2984dcb9bcda0bb8502b6.tar.gz gitea-baed01f24753afb600a2984dcb9bcda0bb8502b6.zip |
Remove unnecessary attributes of User struct (#17745)
* Remove unnecessary functions of User struct
* Move more database methods out of user struct
* Move more database methods out of user struct
* Fix template failure
* Fix bug
* Remove finished FIXME
* remove unnecessary code
Diffstat (limited to 'models/star.go')
-rw-r--r-- | models/star.go | 47 |
1 files changed, 1 insertions, 46 deletions
diff --git a/models/star.go b/models/star.go index baf724d7e0..c0b15be21a 100644 --- a/models/star.go +++ b/models/star.go @@ -74,7 +74,7 @@ func isStaring(e db.Engine, userID, repoID int64) bool { } // GetStargazers returns the users that starred the repo. -func (repo *Repository) GetStargazers(opts db.ListOptions) ([]*User, error) { +func GetStargazers(repo *Repository, opts db.ListOptions) ([]*User, error) { sess := db.GetEngine(db.DefaultContext).Where("star.repo_id = ?", repo.ID). Join("LEFT", "star", "`user`.id = star.uid") if opts.Page > 0 { @@ -87,48 +87,3 @@ func (repo *Repository) GetStargazers(opts db.ListOptions) ([]*User, error) { users := make([]*User, 0, 8) return users, sess.Find(&users) } - -// GetStarredRepos returns the repos the user starred. -func (u *User) GetStarredRepos(private bool, page, pageSize int, orderBy string) (repos RepositoryList, err error) { - if len(orderBy) == 0 { - orderBy = "updated_unix DESC" - } - sess := db.GetEngine(db.DefaultContext). - Join("INNER", "star", "star.repo_id = repository.id"). - Where("star.uid = ?", u.ID). - OrderBy(orderBy) - - if !private { - sess = sess.And("is_private = ?", false) - } - - if page <= 0 { - page = 1 - } - sess.Limit(pageSize, (page-1)*pageSize) - - repos = make([]*Repository, 0, pageSize) - - if err = sess.Find(&repos); err != nil { - return - } - - if err = repos.loadAttributes(db.GetEngine(db.DefaultContext)); err != nil { - return - } - - return -} - -// GetStarredRepoCount returns the numbers of repo the user starred. -func (u *User) GetStarredRepoCount(private bool) (int64, error) { - sess := db.GetEngine(db.DefaultContext). - Join("INNER", "star", "star.repo_id = repository.id"). - Where("star.uid = ?", u.ID) - - if !private { - sess = sess.And("is_private = ?", false) - } - - return sess.Count(&Repository{}) -} |