diff options
author | 6543 <6543@obermui.de> | 2020-02-26 07:32:22 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-26 03:32:22 -0300 |
commit | 084a2b00268ed561f59ac19b1b6660a3c58573b3 (patch) | |
tree | 5474cb8c1bd5a16251edf46cd99d54757e3ebc0c /models/issue_watch.go | |
parent | e5944a9521102c4917399a6550a0756919527944 (diff) | |
download | gitea-084a2b00268ed561f59ac19b1b6660a3c58573b3.tar.gz gitea-084a2b00268ed561f59ac19b1b6660a3c58573b3.zip |
Code Refactor of IssueWatch related things (#10401)
* refactor
* optimize
* remove Iretating function
LoadWatchUsers do not load Users into IW object and it is used only in api ... so move this logic
* remove unessesary
* Apply suggestions from code review
Thx
Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com>
* make Tests more robust
* fix rebase
* restart CI
* CI no dont hit sqlites deadlock
Co-authored-by: guillep2k <18600385+guillep2k@users.noreply.github.com>
Diffstat (limited to 'models/issue_watch.go')
-rw-r--r-- | models/issue_watch.go | 40 |
1 files changed, 7 insertions, 33 deletions
diff --git a/models/issue_watch.go b/models/issue_watch.go index c4732d784e..9046e4d2f7 100644 --- a/models/issue_watch.go +++ b/models/issue_watch.go @@ -68,10 +68,14 @@ func getIssueWatch(e Engine, userID, issueID int64) (iw *IssueWatch, exists bool // but avoids joining with `user` for performance reasons // User permissions must be verified elsewhere if required func GetIssueWatchersIDs(issueID int64) ([]int64, error) { + return getIssueWatchersIDs(x, issueID, true) +} + +func getIssueWatchersIDs(e Engine, issueID int64, watching bool) ([]int64, error) { ids := make([]int64, 0, 64) - return ids, x.Table("issue_watch"). + return ids, e.Table("issue_watch"). Where("issue_id=?", issueID). - And("is_watching = ?", true). + And("is_watching = ?", watching). Select("user_id"). Find(&ids) } @@ -99,39 +103,9 @@ func getIssueWatchers(e Engine, issueID int64, listOptions ListOptions) (IssueWa } func removeIssueWatchersByRepoID(e Engine, userID int64, repoID int64) error { - iw := &IssueWatch{ - IsWatching: false, - } _, err := e. Join("INNER", "issue", "`issue`.id = `issue_watch`.issue_id AND `issue`.repo_id = ?", repoID). - Cols("is_watching", "updated_unix"). Where("`issue_watch`.user_id = ?", userID). - Update(iw) + Delete(new(IssueWatch)) return err } - -// LoadWatchUsers return watching users -func (iwl IssueWatchList) LoadWatchUsers() (users UserList, err error) { - return iwl.loadWatchUsers(x) -} - -func (iwl IssueWatchList) loadWatchUsers(e Engine) (users UserList, err error) { - if len(iwl) == 0 { - return []*User{}, nil - } - - var userIDs = make([]int64, 0, len(iwl)) - for _, iw := range iwl { - if iw.IsWatching { - userIDs = append(userIDs, iw.UserID) - } - } - - if len(userIDs) == 0 { - return []*User{}, nil - } - - err = e.In("id", userIDs).Find(&users) - - return -} |