aboutsummaryrefslogtreecommitdiffstats
path: root/cache/bug_excerpt.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2022-12-23 01:48:14 +0100
committerGitHub <noreply@github.com>2022-12-23 01:48:14 +0100
commit0a5a0ec1ef4ad98bc2116a953e201f96474941ab (patch)
tree660a9b17b5247fe2f954bfa814cce3193c5afa23 /cache/bug_excerpt.go
parent108518530e822e3bdf59c8bfc333ad0bbe2d5fc8 (diff)
parent95911100823b5c809225d664de74ad2d64e91972 (diff)
downloadgit-bug-0a5a0ec1ef4ad98bc2116a953e201f96474941ab.tar.gz
Merge pull request #938 from MichaelMure/cache-reorg
Generic cache layer
Diffstat (limited to 'cache/bug_excerpt.go')
-rw-r--r--cache/bug_excerpt.go48
1 files changed, 16 insertions, 32 deletions
diff --git a/cache/bug_excerpt.go b/cache/bug_excerpt.go
index 7e3bcad4..26b7ec74 100644
--- a/cache/bug_excerpt.go
+++ b/cache/bug_excerpt.go
@@ -2,12 +2,10 @@ package cache
import (
"encoding/gob"
- "fmt"
"time"
"github.com/MichaelMure/git-bug/entities/bug"
"github.com/MichaelMure/git-bug/entities/common"
- "github.com/MichaelMure/git-bug/entities/identity"
"github.com/MichaelMure/git-bug/entity"
"github.com/MichaelMure/git-bug/util/lamport"
)
@@ -17,10 +15,12 @@ func init() {
gob.Register(BugExcerpt{})
}
+var _ Excerpt = &BugExcerpt{}
+
// BugExcerpt hold a subset of the bug values to be able to sort and filter bugs
// efficiently without having to read and compile each raw bugs.
type BugExcerpt struct {
- Id entity.Id
+ id entity.Id
CreateLamportTime lamport.Time
EditLamportTime lamport.Time
@@ -38,26 +38,8 @@ type BugExcerpt struct {
CreateMetadata map[string]string
}
-// identity.Bare data are directly embedded in the bug excerpt
-type LegacyAuthorExcerpt struct {
- Name string
- Login string
-}
-
-func (l LegacyAuthorExcerpt) DisplayName() string {
- switch {
- case l.Name == "" && l.Login != "":
- return l.Login
- case l.Name != "" && l.Login == "":
- return l.Name
- case l.Name != "" && l.Login != "":
- return fmt.Sprintf("%s (%s)", l.Name, l.Login)
- }
-
- panic("invalid person data")
-}
-
-func NewBugExcerpt(b bug.Interface, snap *bug.Snapshot) *BugExcerpt {
+func NewBugExcerpt(b *BugCache) *BugExcerpt {
+ snap := b.Snapshot()
participantsIds := make([]entity.Id, 0, len(snap.Participants))
for _, participant := range snap.Participants {
participantsIds = append(participantsIds, participant.Id())
@@ -69,11 +51,12 @@ func NewBugExcerpt(b bug.Interface, snap *bug.Snapshot) *BugExcerpt {
}
e := &BugExcerpt{
- Id: b.Id(),
+ id: b.Id(),
CreateLamportTime: b.CreateLamportTime(),
EditLamportTime: b.EditLamportTime(),
CreateUnixTime: b.FirstOp().Time().Unix(),
EditUnixTime: snap.EditTime().Unix(),
+ AuthorId: snap.Author.Id(),
Status: snap.Status,
Labels: snap.Labels,
Actors: actorsIds,
@@ -83,16 +66,17 @@ func NewBugExcerpt(b bug.Interface, snap *bug.Snapshot) *BugExcerpt {
CreateMetadata: b.FirstOp().AllMetadata(),
}
- switch snap.Author.(type) {
- case *identity.Identity, *identity.IdentityStub, *IdentityCache:
- e.AuthorId = snap.Author.Id()
- default:
- panic("unhandled identity type")
- }
-
return e
}
+func (b *BugExcerpt) setId(id entity.Id) {
+ b.id = id
+}
+
+func (b *BugExcerpt) Id() entity.Id {
+ return b.id
+}
+
func (b *BugExcerpt) CreateTime() time.Time {
return time.Unix(b.CreateUnixTime, 0)
}
@@ -112,7 +96,7 @@ func (b BugsById) Len() int {
}
func (b BugsById) Less(i, j int) bool {
- return b[i].Id < b[j].Id
+ return b[i].id < b[j].id
}
func (b BugsById) Swap(i, j int) {