Skip to content

Commit

Permalink
Merge pull request #178 from tstromberg/cached-convo
Browse files Browse the repository at this point in the history
optimization: use cached conversations instead of re-parsing
  • Loading branch information
tstromberg committed Jul 11, 2020
2 parents 817ea8f + 217167f commit 69ef214
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pkg/hubbub/hubbub.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ type Engine struct {
// Workaround because GitHub doesn't update issues if cross-references occur
updatedAt map[string]time.Time

// indexes used for similarity matching
// indexes used for similarity matching & conversation caching
seen map[string]*Conversation
}

Expand Down
33 changes: 31 additions & 2 deletions pkg/hubbub/item.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,33 @@ type GitHubItem interface {
String() string
}

// conversation creates a conversation from an issue-like
// conversation returns a cached conversation from an issue-like
func (h *Engine) conversation(i GitHubItem, cs []*Comment, age time.Time) *Conversation {
key := i.GetHTMLURL()
cached, ok := h.seen[key]
if ok {
if cached.Updated != i.GetUpdatedAt() && cached.Updated.Before(i.GetUpdatedAt()) {
klog.V(1).Infof("cache for %s too old: %s, need %s", key, cached.Updated, i.GetUpdatedAt())
h.seen[key] = h.createConversation(i, cs, age)
return h.seen[key]
}

if cached.CommentsTotal < len(cs) {
klog.V(1).Infof("cache for %s has too few comments: %d, need %d", key, cached.CommentsTotal, len(cs))
h.seen[key] = h.createConversation(i, cs, age)
return h.seen[key]
}

return h.seen[key]
}

h.seen[key] = h.createConversation(i, cs, age)
return h.seen[key]
}

// createConversation creates a conversation from an issue-like
func (h *Engine) createConversation(i GitHubItem, cs []*Comment, age time.Time) *Conversation {

authorIsMember := false
if h.isMember(i.GetUser().GetLogin(), i.GetAuthorAssociation()) {
authorIsMember = true
Expand All @@ -78,6 +103,7 @@ func (h *Engine) conversation(i GitHubItem, cs []*Comment, age time.Time) *Conve
Type: Issue,
Seen: age,
Created: i.GetCreatedAt(),
Updated: i.GetUpdatedAt(),
CommentsTotal: i.GetComments(),
ClosedAt: i.GetClosedAt(),
SelfInflicted: authorIsMember,
Expand Down Expand Up @@ -212,7 +238,10 @@ func (h *Engine) conversation(i GitHubItem, cs []*Comment, age time.Time) *Conve
} else {
co.Tags = append(co.Tags, tag.RoleLast(assoc))
}
co.Updated = last.Updated

if last.Updated.After(co.Updated) {
co.Updated = last.Updated
}
}

if co.State == "closed" {
Expand Down
2 changes: 0 additions & 2 deletions pkg/hubbub/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ func (h *Engine) SearchIssues(ctx context.Context, org string, project string, f

co := h.IssueSummary(i, comments, age)
co.Labels = labels
h.seen[co.URL] = co

co.Similar = h.FindSimilar(co)
if len(co.Similar) > 0 {
Expand Down Expand Up @@ -322,7 +321,6 @@ func (h *Engine) SearchPullRequests(ctx context.Context, org string, project str
co.Tags = append(co.Tags, tag.Similar)
}

h.seen[co.URL] = co
if !postFetchMatch(co, fs) {
klog.V(4).Infof("PR #%d did not pass postFetchMatch with filter: %v", pr.GetNumber(), fs)
continue
Expand Down

0 comments on commit 69ef214

Please sign in to comment.