implemet Cache for Stopwatches.APIFormat() (#12730)
Co-authored-by: techknowlogick <techknowlogick@gitea.io>
This commit is contained in:
parent
f10d3ea803
commit
1c35353c53
1 changed files with 31 additions and 4 deletions
|
@ -216,12 +216,39 @@ func (sw *Stopwatch) APIFormat() (api.StopWatch, error) {
|
||||||
// APIFormat convert Stopwatches type to api.StopWatches type
|
// APIFormat convert Stopwatches type to api.StopWatches type
|
||||||
func (sws Stopwatches) APIFormat() (api.StopWatches, error) {
|
func (sws Stopwatches) APIFormat() (api.StopWatches, error) {
|
||||||
result := api.StopWatches(make([]api.StopWatch, 0, len(sws)))
|
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 {
|
for _, sw := range sws {
|
||||||
apiSW, err := sw.APIFormat()
|
issue, ok = issueCache[sw.IssueID]
|
||||||
|
if !ok {
|
||||||
|
issue, err = GetIssueByID(sw.IssueID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
result = append(result, apiSW)
|
}
|
||||||
|
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
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue