aboutsummaryrefslogtreecommitdiffstats
path: root/cache
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2018-09-02 15:46:43 +0200
committerMichael Muré <batolettre@gmail.com>2018-09-02 15:46:43 +0200
commit919f98efdb10d57767cf129c3c0b3c357aaa29d2 (patch)
tree647b2e8092d8f26ae6cafcd3e18ae8db0c7ddac2 /cache
parent90a45b4c0979dd744aa5a28c84ececf243f027d2 (diff)
downloadgit-bug-919f98efdb10d57767cf129c3c0b3c357aaa29d2.tar.gz
cache: provide sorted (id, creation, edit) list of bugs
Diffstat (limited to 'cache')
-rw-r--r--cache/bug_excerpt.go4
-rw-r--r--cache/repo_cache.go55
2 files changed, 55 insertions, 4 deletions
diff --git a/cache/bug_excerpt.go b/cache/bug_excerpt.go
index 572f461a..31e1951f 100644
--- a/cache/bug_excerpt.go
+++ b/cache/bug_excerpt.go
@@ -42,7 +42,7 @@ func init() {
* Sorting
*/
-type BugsByCreationTime []*BugExcerpt
+type BugsByCreationTime []BugExcerpt
func (b BugsByCreationTime) Len() int {
return len(b)
@@ -70,7 +70,7 @@ func (b BugsByCreationTime) Swap(i, j int) {
b[i], b[j] = b[j], b[i]
}
-type BugsByEditTime []*BugExcerpt
+type BugsByEditTime []BugExcerpt
func (b BugsByEditTime) Len() int {
return len(b)
diff --git a/cache/repo_cache.go b/cache/repo_cache.go
index 3ce2f0c2..8f43ad71 100644
--- a/cache/repo_cache.go
+++ b/cache/repo_cache.go
@@ -8,6 +8,7 @@ import (
"io/ioutil"
"os"
"path"
+ "sort"
"strconv"
"strings"
@@ -203,8 +204,58 @@ func (c *RepoCache) ResolveBugPrefix(prefix string) (*BugCache, error) {
return cached, nil
}
-func (c *RepoCache) AllBugIds() ([]string, error) {
- return bug.ListLocalIds(c.repo)
+func (c *RepoCache) AllBugOrderById() []string {
+ result := make([]string, len(c.excerpts))
+
+ i := 0
+ for key := range c.excerpts {
+ result[i] = key
+ i++
+ }
+
+ sort.Strings(result)
+
+ return result
+}
+
+func (c *RepoCache) AllBugsOrderByEdit() []string {
+ excerpts := make([]BugExcerpt, len(c.excerpts))
+
+ i := 0
+ for _, val := range c.excerpts {
+ excerpts[i] = val
+ i++
+ }
+
+ sort.Sort(BugsByEditTime(excerpts))
+
+ result := make([]string, len(excerpts))
+
+ for i, val := range excerpts {
+ result[i] = val.Id
+ }
+
+ return result
+}
+
+func (c *RepoCache) AllBugsOrderByCreation() []string {
+ excerpts := make([]BugExcerpt, len(c.excerpts))
+
+ i := 0
+ for _, val := range c.excerpts {
+ excerpts[i] = val
+ i++
+ }
+
+ sort.Sort(BugsByCreationTime(excerpts))
+
+ result := make([]string, len(excerpts))
+
+ for i, val := range excerpts {
+ result[i] = val.Id
+ }
+
+ return result
}
// ClearAllBugs clear all bugs kept in memory