From 81f5c3e0af9aa4b81662e0781289189703324986 Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Mon, 3 Feb 2020 21:03:48 +0100 Subject: graphql: use the cache in priority for fast browsing at < 20ms instead of seconds --- graphql/models/gen_models.go | 35 ++++--- graphql/models/lazy_bug.go | 214 ++++++++++++++++++++++++++++++++++++++++ graphql/models/lazy_identity.go | 164 ++++++++++++++++++++++++++++++ 3 files changed, 395 insertions(+), 18 deletions(-) create mode 100644 graphql/models/lazy_bug.go create mode 100644 graphql/models/lazy_identity.go (limited to 'graphql/models') diff --git a/graphql/models/gen_models.go b/graphql/models/gen_models.go index 5498960b..b3e14655 100644 --- a/graphql/models/gen_models.go +++ b/graphql/models/gen_models.go @@ -8,7 +8,6 @@ import ( "strconv" "github.com/MichaelMure/git-bug/bug" - "github.com/MichaelMure/git-bug/identity" "github.com/MichaelMure/git-bug/util/git" ) @@ -34,7 +33,7 @@ type AddCommentPayload struct { // A unique identifier for the client performing the mutation. ClientMutationID *string `json:"clientMutationId"` // The affected bug. - Bug *bug.Snapshot `json:"bug"` + Bug BugWrapper `json:"bug"` // The resulting operation. Operation *bug.AddCommentOperation `json:"operation"` } @@ -42,8 +41,8 @@ type AddCommentPayload struct { // The connection type for Bug. type BugConnection struct { // A list of edges. - Edges []*BugEdge `json:"edges"` - Nodes []*bug.Snapshot `json:"nodes"` + Edges []*BugEdge `json:"edges"` + Nodes []BugWrapper `json:"nodes"` // Information to aid in pagination. PageInfo *PageInfo `json:"pageInfo"` // Identifies the total count of items in the connection. @@ -55,7 +54,7 @@ type BugEdge struct { // A cursor for use in pagination. Cursor string `json:"cursor"` // The item at the end of the edge. - Node *bug.Snapshot `json:"node"` + Node BugWrapper `json:"node"` } type ChangeLabelInput struct { @@ -75,7 +74,7 @@ type ChangeLabelPayload struct { // A unique identifier for the client performing the mutation. ClientMutationID *string `json:"clientMutationId"` // The affected bug. - Bug *bug.Snapshot `json:"bug"` + Bug BugWrapper `json:"bug"` // The resulting operation. Operation *bug.LabelChangeOperation `json:"operation"` // The effect each source label had. @@ -95,7 +94,7 @@ type CloseBugPayload struct { // A unique identifier for the client performing the mutation. ClientMutationID *string `json:"clientMutationId"` // The affected bug. - Bug *bug.Snapshot `json:"bug"` + Bug BugWrapper `json:"bug"` // The resulting operation. Operation *bug.SetStatusOperation `json:"operation"` } @@ -125,7 +124,7 @@ type CommitAsNeededPayload struct { // A unique identifier for the client performing the mutation. ClientMutationID *string `json:"clientMutationId"` // The affected bug. - Bug *bug.Snapshot `json:"bug"` + Bug BugWrapper `json:"bug"` } type CommitInput struct { @@ -141,19 +140,19 @@ type CommitPayload struct { // A unique identifier for the client performing the mutation. ClientMutationID *string `json:"clientMutationId"` // The affected bug. - Bug *bug.Snapshot `json:"bug"` + Bug BugWrapper `json:"bug"` } type IdentityConnection struct { - Edges []*IdentityEdge `json:"edges"` - Nodes []identity.Interface `json:"nodes"` - PageInfo *PageInfo `json:"pageInfo"` - TotalCount int `json:"totalCount"` + Edges []*IdentityEdge `json:"edges"` + Nodes []IdentityWrapper `json:"nodes"` + PageInfo *PageInfo `json:"pageInfo"` + TotalCount int `json:"totalCount"` } type IdentityEdge struct { - Cursor string `json:"cursor"` - Node identity.Interface `json:"node"` + Cursor string `json:"cursor"` + Node IdentityWrapper `json:"node"` } type LabelConnection struct { @@ -185,7 +184,7 @@ type NewBugPayload struct { // A unique identifier for the client performing the mutation. ClientMutationID *string `json:"clientMutationId"` // The created bug. - Bug *bug.Snapshot `json:"bug"` + Bug BugWrapper `json:"bug"` // The resulting operation. Operation *bug.CreateOperation `json:"operation"` } @@ -203,7 +202,7 @@ type OpenBugPayload struct { // A unique identifier for the client performing the mutation. ClientMutationID *string `json:"clientMutationId"` // The affected bug. - Bug *bug.Snapshot `json:"bug"` + Bug BugWrapper `json:"bug"` // The resulting operation. Operation *bug.SetStatusOperation `json:"operation"` } @@ -249,7 +248,7 @@ type SetTitlePayload struct { // A unique identifier for the client performing the mutation. ClientMutationID *string `json:"clientMutationId"` // The affected bug. - Bug *bug.Snapshot `json:"bug"` + Bug BugWrapper `json:"bug"` // The resulting operation Operation *bug.SetTitleOperation `json:"operation"` } diff --git a/graphql/models/lazy_bug.go b/graphql/models/lazy_bug.go new file mode 100644 index 00000000..b02f781c --- /dev/null +++ b/graphql/models/lazy_bug.go @@ -0,0 +1,214 @@ +package models + +import ( + "sync" + "time" + + "github.com/MichaelMure/git-bug/bug" + "github.com/MichaelMure/git-bug/cache" + "github.com/MichaelMure/git-bug/entity" +) + +type BugWrapper interface { + Id() entity.Id + LastEdit() time.Time + Status() bug.Status + Title() string + Comments() ([]bug.Comment, error) + Labels() []bug.Label + Author() (IdentityWrapper, error) + Actors() ([]IdentityWrapper, error) + Participants() ([]IdentityWrapper, error) + CreatedAt() time.Time + Timeline() ([]bug.TimelineItem, error) + Operations() ([]bug.Operation, error) + + IsAuthored() +} + +var _ BugWrapper = &LazyBug{} + +type LazyBug struct { + cache *cache.RepoCache + excerpt *cache.BugExcerpt + + mu sync.Mutex + snap *bug.Snapshot +} + +func NewLazyBug(cache *cache.RepoCache, excerpt *cache.BugExcerpt) *LazyBug { + return &LazyBug{ + cache: cache, + excerpt: excerpt, + } +} + +func (lb *LazyBug) load() error { + if lb.snap != nil { + return nil + } + + lb.mu.Lock() + defer lb.mu.Unlock() + + b, err := lb.cache.ResolveBug(lb.excerpt.Id) + if err != nil { + return err + } + + lb.snap = b.Snapshot() + return nil +} + +func (lb *LazyBug) identity(id entity.Id) (IdentityWrapper, error) { + i, err := lb.cache.ResolveIdentityExcerpt(id) + if err != nil { + return nil, err + } + return &LazyIdentity{cache: lb.cache, excerpt: i}, nil +} + +// Sign post method for gqlgen +func (lb *LazyBug) IsAuthored() {} + +func (lb *LazyBug) Id() entity.Id { + return lb.excerpt.Id +} + +func (lb *LazyBug) LastEdit() time.Time { + return time.Unix(lb.excerpt.EditUnixTime, 0) +} + +func (lb *LazyBug) Status() bug.Status { + return lb.excerpt.Status +} + +func (lb *LazyBug) Title() string { + return lb.excerpt.Title +} + +func (lb *LazyBug) Comments() ([]bug.Comment, error) { + err := lb.load() + if err != nil { + return nil, err + } + return lb.snap.Comments, nil +} + +func (lb *LazyBug) Labels() []bug.Label { + return lb.excerpt.Labels +} + +func (lb *LazyBug) Author() (IdentityWrapper, error) { + return lb.identity(lb.excerpt.AuthorId) +} + +func (lb *LazyBug) Actors() ([]IdentityWrapper, error) { + result := make([]IdentityWrapper, len(lb.excerpt.Actors)) + for i, actorId := range lb.excerpt.Actors { + actor, err := lb.identity(actorId) + if err != nil { + return nil, err + } + result[i] = actor + } + return result, nil +} + +func (lb *LazyBug) Participants() ([]IdentityWrapper, error) { + result := make([]IdentityWrapper, len(lb.excerpt.Participants)) + for i, participantId := range lb.excerpt.Participants { + participant, err := lb.identity(participantId) + if err != nil { + return nil, err + } + result[i] = participant + } + return result, nil +} + +func (lb *LazyBug) CreatedAt() time.Time { + return time.Unix(lb.excerpt.CreateUnixTime, 0) +} + +func (lb *LazyBug) Timeline() ([]bug.TimelineItem, error) { + err := lb.load() + if err != nil { + return nil, err + } + return lb.snap.Timeline, nil +} + +func (lb *LazyBug) Operations() ([]bug.Operation, error) { + err := lb.load() + if err != nil { + return nil, err + } + result := make([]bug.Operation, len(lb.snap.Operations)) + for i, operation := range lb.snap.Operations { + result[i] = operation + } + return result, nil +} + +var _ BugWrapper = &LoadedBug{} + +type LoadedBug struct { + *bug.Snapshot +} + +func NewLoadedBug(snap *bug.Snapshot) *LoadedBug { + return &LoadedBug{Snapshot: snap} +} + +func (l *LoadedBug) LastEdit() time.Time { + return l.Snapshot.LastEditTime() +} + +func (l *LoadedBug) Status() bug.Status { + return l.Snapshot.Status +} + +func (l *LoadedBug) Title() string { + return l.Snapshot.Title +} + +func (l *LoadedBug) Comments() ([]bug.Comment, error) { + return l.Snapshot.Comments, nil +} + +func (l *LoadedBug) Labels() []bug.Label { + return l.Snapshot.Labels +} + +func (l *LoadedBug) Author() (IdentityWrapper, error) { + return NewLoadedIdentity(l.Snapshot.Author), nil +} + +func (l *LoadedBug) Actors() ([]IdentityWrapper, error) { + res := make([]IdentityWrapper, len(l.Snapshot.Actors)) + for i, actor := range l.Snapshot.Actors { + res[i] = NewLoadedIdentity(actor) + } + return res, nil +} + +func (l *LoadedBug) Participants() ([]IdentityWrapper, error) { + res := make([]IdentityWrapper, len(l.Snapshot.Participants)) + for i, participant := range l.Snapshot.Participants { + res[i] = NewLoadedIdentity(participant) + } + return res, nil +} + +func (l *LoadedBug) CreatedAt() time.Time { + return l.Snapshot.CreatedAt +} + +func (l *LoadedBug) Timeline() ([]bug.TimelineItem, error) { + return l.Snapshot.Timeline, nil +} + +func (l *LoadedBug) Operations() ([]bug.Operation, error) { + return l.Snapshot.Operations, nil +} diff --git a/graphql/models/lazy_identity.go b/graphql/models/lazy_identity.go new file mode 100644 index 00000000..31f4dcc4 --- /dev/null +++ b/graphql/models/lazy_identity.go @@ -0,0 +1,164 @@ +package models + +import ( + "fmt" + "sync" + + "github.com/MichaelMure/git-bug/cache" + "github.com/MichaelMure/git-bug/entity" + "github.com/MichaelMure/git-bug/identity" + "github.com/MichaelMure/git-bug/util/lamport" + "github.com/MichaelMure/git-bug/util/timestamp" +) + +type IdentityWrapper interface { + Id() entity.Id + Name() string + Email() (string, error) + AvatarUrl() (string, error) + Keys() ([]*identity.Key, error) + ValidKeysAtTime(time lamport.Time) ([]*identity.Key, error) + DisplayName() string + IsProtected() (bool, error) + LastModificationLamport() (lamport.Time, error) + LastModification() (timestamp.Timestamp, error) +} + +var _ IdentityWrapper = &LazyIdentity{} + +type LazyIdentity struct { + cache *cache.RepoCache + excerpt *cache.IdentityExcerpt + + mu sync.Mutex + id *cache.IdentityCache +} + +func NewLazyIdentity(cache *cache.RepoCache, excerpt *cache.IdentityExcerpt) *LazyIdentity { + return &LazyIdentity{ + cache: cache, + excerpt: excerpt, + } +} + +func (li *LazyIdentity) load() (*cache.IdentityCache, error) { + if li.id != nil { + return li.id, nil + } + + li.mu.Lock() + defer li.mu.Unlock() + + id, err := li.cache.ResolveIdentity(li.excerpt.Id) + if err != nil { + return nil, fmt.Errorf("cache: missing identity %v", li.excerpt.Id) + } + li.id = id + return id, nil +} + +func (li *LazyIdentity) Id() entity.Id { + return li.excerpt.Id +} + +func (li *LazyIdentity) Name() string { + return li.excerpt.Name +} + +func (li *LazyIdentity) Email() (string, error) { + id, err := li.load() + if err != nil { + return "", err + } + return id.Email(), nil +} + +func (li *LazyIdentity) AvatarUrl() (string, error) { + id, err := li.load() + if err != nil { + return "", err + } + return id.AvatarUrl(), nil +} + +func (li *LazyIdentity) Keys() ([]*identity.Key, error) { + id, err := li.load() + if err != nil { + return nil, err + } + return id.Keys(), nil +} + +func (li *LazyIdentity) ValidKeysAtTime(time lamport.Time) ([]*identity.Key, error) { + id, err := li.load() + if err != nil { + return nil, err + } + return id.ValidKeysAtTime(time), nil +} + +func (li *LazyIdentity) DisplayName() string { + return li.excerpt.DisplayName() +} + +func (li *LazyIdentity) IsProtected() (bool, error) { + id, err := li.load() + if err != nil { + return false, err + } + return id.IsProtected(), nil +} + +func (li *LazyIdentity) LastModificationLamport() (lamport.Time, error) { + id, err := li.load() + if err != nil { + return 0, err + } + return id.LastModificationLamport(), nil +} + +func (li *LazyIdentity) LastModification() (timestamp.Timestamp, error) { + id, err := li.load() + if err != nil { + return 0, err + } + return id.LastModification(), nil +} + +var _ IdentityWrapper = &LoadedIdentity{} + +type LoadedIdentity struct { + identity.Interface +} + +func NewLoadedIdentity(id identity.Interface) *LoadedIdentity { + return &LoadedIdentity{Interface: id} +} + +func (l LoadedIdentity) Email() (string, error) { + return l.Interface.Email(), nil +} + +func (l LoadedIdentity) AvatarUrl() (string, error) { + return l.Interface.AvatarUrl(), nil +} + +func (l LoadedIdentity) Keys() ([]*identity.Key, error) { + return l.Interface.Keys(), nil +} + +func (l LoadedIdentity) ValidKeysAtTime(time lamport.Time) ([]*identity.Key, error) { + return l.Interface.ValidKeysAtTime(time), nil +} + +func (l LoadedIdentity) IsProtected() (bool, error) { + return l.Interface.IsProtected(), nil +} + +func (l LoadedIdentity) LastModificationLamport() (lamport.Time, error) { + return l.Interface.LastModificationLamport(), nil +} + +func (l LoadedIdentity) LastModification() (timestamp.Timestamp, error) { + return l.Interface.LastModification(), nil +} -- cgit From d78ed55173935e85673a0b2270d421540baf72fb Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Sat, 8 Feb 2020 16:02:49 +0100 Subject: cleanups, doc --- graphql/models/lazy_bug.go | 81 +++++++++++++++++++++-------------------- graphql/models/lazy_identity.go | 55 +++++++++++++++------------- 2 files changed, 70 insertions(+), 66 deletions(-) (limited to 'graphql/models') diff --git a/graphql/models/lazy_bug.go b/graphql/models/lazy_bug.go index b02f781c..6034e80d 100644 --- a/graphql/models/lazy_bug.go +++ b/graphql/models/lazy_bug.go @@ -9,6 +9,9 @@ import ( "github.com/MichaelMure/git-bug/entity" ) +// BugWrapper is an interface used by the GraphQL resolvers to handle a bug. +// Depending on the situation, a Bug can already be fully loaded in memory or not. +// This interface is used to wrap either a lazyBug or a loadedBug depending on the situation. type BugWrapper interface { Id() entity.Id LastEdit() time.Time @@ -26,9 +29,11 @@ type BugWrapper interface { IsAuthored() } -var _ BugWrapper = &LazyBug{} +var _ BugWrapper = &lazyBug{} -type LazyBug struct { +// lazyBug is a lazy-loading wrapper that fetch data from the cache (BugExcerpt) in priority, +// and load the complete bug and snapshot only when necessary. +type lazyBug struct { cache *cache.RepoCache excerpt *cache.BugExcerpt @@ -36,14 +41,14 @@ type LazyBug struct { snap *bug.Snapshot } -func NewLazyBug(cache *cache.RepoCache, excerpt *cache.BugExcerpt) *LazyBug { - return &LazyBug{ +func NewLazyBug(cache *cache.RepoCache, excerpt *cache.BugExcerpt) *lazyBug { + return &lazyBug{ cache: cache, excerpt: excerpt, } } -func (lb *LazyBug) load() error { +func (lb *lazyBug) load() error { if lb.snap != nil { return nil } @@ -60,34 +65,34 @@ func (lb *LazyBug) load() error { return nil } -func (lb *LazyBug) identity(id entity.Id) (IdentityWrapper, error) { +func (lb *lazyBug) identity(id entity.Id) (IdentityWrapper, error) { i, err := lb.cache.ResolveIdentityExcerpt(id) if err != nil { return nil, err } - return &LazyIdentity{cache: lb.cache, excerpt: i}, nil + return &lazyIdentity{cache: lb.cache, excerpt: i}, nil } // Sign post method for gqlgen -func (lb *LazyBug) IsAuthored() {} +func (lb *lazyBug) IsAuthored() {} -func (lb *LazyBug) Id() entity.Id { +func (lb *lazyBug) Id() entity.Id { return lb.excerpt.Id } -func (lb *LazyBug) LastEdit() time.Time { +func (lb *lazyBug) LastEdit() time.Time { return time.Unix(lb.excerpt.EditUnixTime, 0) } -func (lb *LazyBug) Status() bug.Status { +func (lb *lazyBug) Status() bug.Status { return lb.excerpt.Status } -func (lb *LazyBug) Title() string { +func (lb *lazyBug) Title() string { return lb.excerpt.Title } -func (lb *LazyBug) Comments() ([]bug.Comment, error) { +func (lb *lazyBug) Comments() ([]bug.Comment, error) { err := lb.load() if err != nil { return nil, err @@ -95,15 +100,15 @@ func (lb *LazyBug) Comments() ([]bug.Comment, error) { return lb.snap.Comments, nil } -func (lb *LazyBug) Labels() []bug.Label { +func (lb *lazyBug) Labels() []bug.Label { return lb.excerpt.Labels } -func (lb *LazyBug) Author() (IdentityWrapper, error) { +func (lb *lazyBug) Author() (IdentityWrapper, error) { return lb.identity(lb.excerpt.AuthorId) } -func (lb *LazyBug) Actors() ([]IdentityWrapper, error) { +func (lb *lazyBug) Actors() ([]IdentityWrapper, error) { result := make([]IdentityWrapper, len(lb.excerpt.Actors)) for i, actorId := range lb.excerpt.Actors { actor, err := lb.identity(actorId) @@ -115,7 +120,7 @@ func (lb *LazyBug) Actors() ([]IdentityWrapper, error) { return result, nil } -func (lb *LazyBug) Participants() ([]IdentityWrapper, error) { +func (lb *lazyBug) Participants() ([]IdentityWrapper, error) { result := make([]IdentityWrapper, len(lb.excerpt.Participants)) for i, participantId := range lb.excerpt.Participants { participant, err := lb.identity(participantId) @@ -127,11 +132,11 @@ func (lb *LazyBug) Participants() ([]IdentityWrapper, error) { return result, nil } -func (lb *LazyBug) CreatedAt() time.Time { +func (lb *lazyBug) CreatedAt() time.Time { return time.Unix(lb.excerpt.CreateUnixTime, 0) } -func (lb *LazyBug) Timeline() ([]bug.TimelineItem, error) { +func (lb *lazyBug) Timeline() ([]bug.TimelineItem, error) { err := lb.load() if err != nil { return nil, err @@ -139,53 +144,49 @@ func (lb *LazyBug) Timeline() ([]bug.TimelineItem, error) { return lb.snap.Timeline, nil } -func (lb *LazyBug) Operations() ([]bug.Operation, error) { +func (lb *lazyBug) Operations() ([]bug.Operation, error) { err := lb.load() if err != nil { return nil, err } - result := make([]bug.Operation, len(lb.snap.Operations)) - for i, operation := range lb.snap.Operations { - result[i] = operation - } - return result, nil + return lb.snap.Operations, nil } -var _ BugWrapper = &LoadedBug{} +var _ BugWrapper = &loadedBug{} -type LoadedBug struct { +type loadedBug struct { *bug.Snapshot } -func NewLoadedBug(snap *bug.Snapshot) *LoadedBug { - return &LoadedBug{Snapshot: snap} +func NewLoadedBug(snap *bug.Snapshot) *loadedBug { + return &loadedBug{Snapshot: snap} } -func (l *LoadedBug) LastEdit() time.Time { +func (l *loadedBug) LastEdit() time.Time { return l.Snapshot.LastEditTime() } -func (l *LoadedBug) Status() bug.Status { +func (l *loadedBug) Status() bug.Status { return l.Snapshot.Status } -func (l *LoadedBug) Title() string { +func (l *loadedBug) Title() string { return l.Snapshot.Title } -func (l *LoadedBug) Comments() ([]bug.Comment, error) { +func (l *loadedBug) Comments() ([]bug.Comment, error) { return l.Snapshot.Comments, nil } -func (l *LoadedBug) Labels() []bug.Label { +func (l *loadedBug) Labels() []bug.Label { return l.Snapshot.Labels } -func (l *LoadedBug) Author() (IdentityWrapper, error) { +func (l *loadedBug) Author() (IdentityWrapper, error) { return NewLoadedIdentity(l.Snapshot.Author), nil } -func (l *LoadedBug) Actors() ([]IdentityWrapper, error) { +func (l *loadedBug) Actors() ([]IdentityWrapper, error) { res := make([]IdentityWrapper, len(l.Snapshot.Actors)) for i, actor := range l.Snapshot.Actors { res[i] = NewLoadedIdentity(actor) @@ -193,7 +194,7 @@ func (l *LoadedBug) Actors() ([]IdentityWrapper, error) { return res, nil } -func (l *LoadedBug) Participants() ([]IdentityWrapper, error) { +func (l *loadedBug) Participants() ([]IdentityWrapper, error) { res := make([]IdentityWrapper, len(l.Snapshot.Participants)) for i, participant := range l.Snapshot.Participants { res[i] = NewLoadedIdentity(participant) @@ -201,14 +202,14 @@ func (l *LoadedBug) Participants() ([]IdentityWrapper, error) { return res, nil } -func (l *LoadedBug) CreatedAt() time.Time { +func (l *loadedBug) CreatedAt() time.Time { return l.Snapshot.CreatedAt } -func (l *LoadedBug) Timeline() ([]bug.TimelineItem, error) { +func (l *loadedBug) Timeline() ([]bug.TimelineItem, error) { return l.Snapshot.Timeline, nil } -func (l *LoadedBug) Operations() ([]bug.Operation, error) { +func (l *loadedBug) Operations() ([]bug.Operation, error) { return l.Snapshot.Operations, nil } diff --git a/graphql/models/lazy_identity.go b/graphql/models/lazy_identity.go index 31f4dcc4..bbd36be3 100644 --- a/graphql/models/lazy_identity.go +++ b/graphql/models/lazy_identity.go @@ -11,6 +11,9 @@ import ( "github.com/MichaelMure/git-bug/util/timestamp" ) +// IdentityWrapper is an interface used by the GraphQL resolvers to handle an identity. +// Depending on the situation, an Identity can already be fully loaded in memory or not. +// This interface is used to wrap either a lazyIdentity or a loadedIdentity depending on the situation. type IdentityWrapper interface { Id() entity.Id Name() string @@ -24,9 +27,9 @@ type IdentityWrapper interface { LastModification() (timestamp.Timestamp, error) } -var _ IdentityWrapper = &LazyIdentity{} +var _ IdentityWrapper = &lazyIdentity{} -type LazyIdentity struct { +type lazyIdentity struct { cache *cache.RepoCache excerpt *cache.IdentityExcerpt @@ -34,14 +37,14 @@ type LazyIdentity struct { id *cache.IdentityCache } -func NewLazyIdentity(cache *cache.RepoCache, excerpt *cache.IdentityExcerpt) *LazyIdentity { - return &LazyIdentity{ +func NewLazyIdentity(cache *cache.RepoCache, excerpt *cache.IdentityExcerpt) *lazyIdentity { + return &lazyIdentity{ cache: cache, excerpt: excerpt, } } -func (li *LazyIdentity) load() (*cache.IdentityCache, error) { +func (li *lazyIdentity) load() (*cache.IdentityCache, error) { if li.id != nil { return li.id, nil } @@ -57,15 +60,15 @@ func (li *LazyIdentity) load() (*cache.IdentityCache, error) { return id, nil } -func (li *LazyIdentity) Id() entity.Id { +func (li *lazyIdentity) Id() entity.Id { return li.excerpt.Id } -func (li *LazyIdentity) Name() string { +func (li *lazyIdentity) Name() string { return li.excerpt.Name } -func (li *LazyIdentity) Email() (string, error) { +func (li *lazyIdentity) Email() (string, error) { id, err := li.load() if err != nil { return "", err @@ -73,7 +76,7 @@ func (li *LazyIdentity) Email() (string, error) { return id.Email(), nil } -func (li *LazyIdentity) AvatarUrl() (string, error) { +func (li *lazyIdentity) AvatarUrl() (string, error) { id, err := li.load() if err != nil { return "", err @@ -81,7 +84,7 @@ func (li *LazyIdentity) AvatarUrl() (string, error) { return id.AvatarUrl(), nil } -func (li *LazyIdentity) Keys() ([]*identity.Key, error) { +func (li *lazyIdentity) Keys() ([]*identity.Key, error) { id, err := li.load() if err != nil { return nil, err @@ -89,7 +92,7 @@ func (li *LazyIdentity) Keys() ([]*identity.Key, error) { return id.Keys(), nil } -func (li *LazyIdentity) ValidKeysAtTime(time lamport.Time) ([]*identity.Key, error) { +func (li *lazyIdentity) ValidKeysAtTime(time lamport.Time) ([]*identity.Key, error) { id, err := li.load() if err != nil { return nil, err @@ -97,11 +100,11 @@ func (li *LazyIdentity) ValidKeysAtTime(time lamport.Time) ([]*identity.Key, err return id.ValidKeysAtTime(time), nil } -func (li *LazyIdentity) DisplayName() string { +func (li *lazyIdentity) DisplayName() string { return li.excerpt.DisplayName() } -func (li *LazyIdentity) IsProtected() (bool, error) { +func (li *lazyIdentity) IsProtected() (bool, error) { id, err := li.load() if err != nil { return false, err @@ -109,7 +112,7 @@ func (li *LazyIdentity) IsProtected() (bool, error) { return id.IsProtected(), nil } -func (li *LazyIdentity) LastModificationLamport() (lamport.Time, error) { +func (li *lazyIdentity) LastModificationLamport() (lamport.Time, error) { id, err := li.load() if err != nil { return 0, err @@ -117,7 +120,7 @@ func (li *LazyIdentity) LastModificationLamport() (lamport.Time, error) { return id.LastModificationLamport(), nil } -func (li *LazyIdentity) LastModification() (timestamp.Timestamp, error) { +func (li *lazyIdentity) LastModification() (timestamp.Timestamp, error) { id, err := li.load() if err != nil { return 0, err @@ -125,40 +128,40 @@ func (li *LazyIdentity) LastModification() (timestamp.Timestamp, error) { return id.LastModification(), nil } -var _ IdentityWrapper = &LoadedIdentity{} +var _ IdentityWrapper = &loadedIdentity{} -type LoadedIdentity struct { +type loadedIdentity struct { identity.Interface } -func NewLoadedIdentity(id identity.Interface) *LoadedIdentity { - return &LoadedIdentity{Interface: id} +func NewLoadedIdentity(id identity.Interface) *loadedIdentity { + return &loadedIdentity{Interface: id} } -func (l LoadedIdentity) Email() (string, error) { +func (l loadedIdentity) Email() (string, error) { return l.Interface.Email(), nil } -func (l LoadedIdentity) AvatarUrl() (string, error) { +func (l loadedIdentity) AvatarUrl() (string, error) { return l.Interface.AvatarUrl(), nil } -func (l LoadedIdentity) Keys() ([]*identity.Key, error) { +func (l loadedIdentity) Keys() ([]*identity.Key, error) { return l.Interface.Keys(), nil } -func (l LoadedIdentity) ValidKeysAtTime(time lamport.Time) ([]*identity.Key, error) { +func (l loadedIdentity) ValidKeysAtTime(time lamport.Time) ([]*identity.Key, error) { return l.Interface.ValidKeysAtTime(time), nil } -func (l LoadedIdentity) IsProtected() (bool, error) { +func (l loadedIdentity) IsProtected() (bool, error) { return l.Interface.IsProtected(), nil } -func (l LoadedIdentity) LastModificationLamport() (lamport.Time, error) { +func (l loadedIdentity) LastModificationLamport() (lamport.Time, error) { return l.Interface.LastModificationLamport(), nil } -func (l LoadedIdentity) LastModification() (timestamp.Timestamp, error) { +func (l loadedIdentity) LastModification() (timestamp.Timestamp, error) { return l.Interface.LastModification(), nil } -- cgit