diff options
author | Michael Muré <batolettre@gmail.com> | 2019-02-18 14:11:37 +0100 |
---|---|---|
committer | Michael Muré <batolettre@gmail.com> | 2019-03-01 22:40:26 +0100 |
commit | 947ea63522610bd16c32cf70812c129eda9bbb02 (patch) | |
tree | 76542e4a5ab488dc45477d33c3f4e94b0eb36975 /cache/identity_excerpt.go | |
parent | 976af3a4e8382d03e9f2ccb57e2ed3b783294138 (diff) | |
download | git-bug-947ea63522610bd16c32cf70812c129eda9bbb02.tar.gz |
identity: wip caching
Diffstat (limited to 'cache/identity_excerpt.go')
-rw-r--r-- | cache/identity_excerpt.go | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/cache/identity_excerpt.go b/cache/identity_excerpt.go new file mode 100644 index 00000000..7bc660b6 --- /dev/null +++ b/cache/identity_excerpt.go @@ -0,0 +1,48 @@ +package cache + +import ( + "encoding/gob" + + "github.com/MichaelMure/git-bug/identity" +) + +// IdentityExcerpt hold a subset of the identity values to be able to sort and +// filter identities efficiently without having to read and compile each raw +// identity. +type IdentityExcerpt struct { + Id string + + Name string + Login string +} + +func NewIdentityExcerpt(i *identity.Identity) *IdentityExcerpt { + return &IdentityExcerpt{ + Id: i.Id(), + Name: i.Name(), + Login: i.Login(), + } +} + +// Package initialisation used to register the type for (de)serialization +func init() { + gob.Register(IdentityExcerpt{}) +} + +/* + * Sorting + */ + +type IdentityById []*IdentityExcerpt + +func (b IdentityById) Len() int { + return len(b) +} + +func (b IdentityById) Less(i, j int) bool { + return b[i].Id < b[j].Id +} + +func (b IdentityById) Swap(i, j int) { + b[i], b[j] = b[j], b[i] +} |