diff options
Diffstat (limited to 'models/issue_stopwatch.go')
-rw-r--r-- | models/issue_stopwatch.go | 68 |
1 files changed, 3 insertions, 65 deletions
diff --git a/models/issue_stopwatch.go b/models/issue_stopwatch.go index 789f8ebdfc..4b2bf1505d 100644 --- a/models/issue_stopwatch.go +++ b/models/issue_stopwatch.go @@ -8,7 +8,6 @@ import ( "fmt" "time" - api "code.gitea.io/gitea/modules/structs" "code.gitea.io/gitea/modules/timeutil" ) @@ -20,9 +19,6 @@ type Stopwatch struct { CreatedUnix timeutil.TimeStamp `xorm:"created"` } -// Stopwatches is a List ful of Stopwatch -type Stopwatches []Stopwatch - func getStopwatch(e Engine, userID, issueID int64) (sw *Stopwatch, exists bool, err error) { sw = new(Stopwatch) exists, err = e. @@ -33,14 +29,14 @@ func getStopwatch(e Engine, userID, issueID int64) (sw *Stopwatch, exists bool, } // GetUserStopwatches return list of all stopwatches of a user -func GetUserStopwatches(userID int64, listOptions ListOptions) (*Stopwatches, error) { - sws := new(Stopwatches) +func GetUserStopwatches(userID int64, listOptions ListOptions) ([]*Stopwatch, error) { + sws := make([]*Stopwatch, 0, 8) sess := x.Where("stopwatch.user_id = ?", userID) if listOptions.Page != 0 { sess = listOptions.setSessionPagination(sess) } - err := sess.Find(sws) + err := sess.Find(&sws) if err != nil { return nil, err } @@ -194,61 +190,3 @@ func SecToTime(duration int64) string { return hrs } - -// APIFormat convert Stopwatch type to api.StopWatch type -func (sw *Stopwatch) APIFormat() (api.StopWatch, error) { - issue, err := getIssueByID(x, sw.IssueID) - if err != nil { - return api.StopWatch{}, err - } - if err := issue.LoadRepo(); err != nil { - return api.StopWatch{}, err - } - return api.StopWatch{ - Created: sw.CreatedUnix.AsTime(), - IssueIndex: issue.Index, - IssueTitle: issue.Title, - RepoOwnerName: issue.Repo.OwnerName, - RepoName: issue.Repo.Name, - }, nil -} - -// APIFormat convert Stopwatches type to api.StopWatches type -func (sws Stopwatches) APIFormat() (api.StopWatches, error) { - result := api.StopWatches(make([]api.StopWatch, 0, len(sws))) - - issueCache := make(map[int64]*Issue) - repoCache := make(map[int64]*Repository) - var ( - issue *Issue - repo *Repository - ok bool - err error - ) - - for _, sw := range sws { - issue, ok = issueCache[sw.IssueID] - if !ok { - issue, err = GetIssueByID(sw.IssueID) - if err != nil { - return nil, err - } - } - repo, ok = repoCache[issue.RepoID] - if !ok { - repo, err = GetRepositoryByID(issue.RepoID) - if err != nil { - return nil, err - } - } - - result = append(result, api.StopWatch{ - Created: sw.CreatedUnix.AsTime(), - IssueIndex: issue.Index, - IssueTitle: issue.Title, - RepoOwnerName: repo.OwnerName, - RepoName: repo.Name, - }) - } - return result, nil -} |