Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make timeline cache date calculation smarter #141

Merged
merged 1 commit into from
Jun 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion pkg/hubbub/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,14 @@ func (h *Engine) SearchIssues(ctx context.Context, org string, project string, f
var filtered []*Conversation
klog.V(1).Infof("%s/%s aggregate issue count: %d, filtering for:\n%s", org, project, len(is), toYAML(fs))

// Avoids updating PR references on a quiet repository
mostRecentUpdate := time.Time{}
for _, i := range is {
if i.GetUpdatedAt().After(mostRecentUpdate) {
mostRecentUpdate = i.GetUpdatedAt()
}
}

for _, i := range is {
// Inconsistency warning: issues use a list of labels, prs a list of label pointers
labels := []*github.Label{}
Expand Down Expand Up @@ -157,7 +165,7 @@ func (h *Engine) SearchIssues(ctx context.Context, org string, project string, f

// Some labels are judged by linked PR state. Ensure that they are updated to the same timestamp.
if len(co.PullRequestRefs) > 0 {
co.PullRequestRefs = h.updateLinkedPRs(ctx, co, age)
co.PullRequestRefs = h.updateLinkedPRs(ctx, co, mostRecentUpdate)
}

if !postEventsMatch(co, fs) {
Expand Down
18 changes: 14 additions & 4 deletions pkg/hubbub/timeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ func (h *Engine) cachedTimeline(ctx context.Context, org string, project string,
return x.Timeline, nil
}

klog.V(1).Infof("cache miss for %s newer than %s", key, newerThan)
klog.Infof("cache miss for %s newer than %s", key, newerThan)
return h.updateTimeline(ctx, org, project, num, key)
}

func (h *Engine) updateTimeline(ctx context.Context, org string, project string, num int, key string) ([]*github.Timeline, error) {
klog.Infof("Downloading event timeline for %s/%s #%d", org, project, num)
// klog.Infof("Downloading event timeline for %s/%s #%d", org, project, num)

opt := &github.ListOptions{
PerPage: 100,
Expand Down Expand Up @@ -118,7 +118,7 @@ func (h *Engine) addEvents(ctx context.Context, co *Conversation, timeline []*gi
continue
}

ref := h.prRef(ctx, ri, co.Seen)
ref := h.prRef(ctx, ri, co.Updated)
co.PullRequestRefs = append(co.PullRequestRefs, ref)
refTag := reviewStateTag(ref.ReviewState)
refTag.ID = fmt.Sprintf("pr-%s", refTag.ID)
Expand All @@ -139,6 +139,10 @@ func (h *Engine) prRef(ctx context.Context, pr GitHubItem, age time.Time) *Relat
newerThan = h.mtime(pr)
}

if !pr.GetClosedAt().IsZero() {
newerThan = pr.GetClosedAt()
}

klog.V(1).Infof("Creating PR reference for #%d, updated at %s(state=%s)", pr.GetNumber(), pr.GetUpdatedAt(), pr.GetState())

co := h.conversation(pr, nil, age)
Expand Down Expand Up @@ -172,13 +176,19 @@ func (h *Engine) prRef(ctx context.Context, pr GitHubItem, age time.Time) *Relat
func (h *Engine) updateLinkedPRs(ctx context.Context, parent *Conversation, newerThan time.Time) []*RelatedConversation {
newRefs := []*RelatedConversation{}

for _, ref := range parent.PullRequestRefs {
if h.mtimeRef(ref).After(newerThan) {
newerThan = h.mtimeRef(ref)
}
}

for _, ref := range parent.PullRequestRefs {
if newerThan.Before(ref.Seen) || newerThan == ref.Seen {
newRefs = append(newRefs, ref)
continue
}

klog.Infof("updating PR ref: %s/%s #%d from %s to %s", ref.Organization, ref.Project, ref.ID, ref.Seen, newerThan)
klog.V(1).Infof("updating PR ref: %s/%s #%d from %s to %s", ref.Organization, ref.Project, ref.ID, ref.Seen, newerThan)
pr, age, err := h.cachedPR(ctx, ref.Organization, ref.Project, ref.ID, newerThan)
if err != nil {
klog.Errorf("error updating cached PR: %v", err)
Expand Down
20 changes: 20 additions & 0 deletions pkg/hubbub/update_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,26 @@ func (h *Engine) mtime(i GitHubItem) time.Time {
return updatedAt
}

// mtimeRef is like mtime, but for related conversations
func (h *Engine) mtimeRef(rc *RelatedConversation) time.Time {
updatedAt := rc.Updated
key := fmt.Sprintf("%s/%s#%d", rc.Organization, rc.Project, rc.ID)
updateSeen := h.updatedAt[key]

if updateSeen == updatedAt {
return updatedAt
}

if updateSeen.After(updatedAt) {
klog.V(1).Infof("%s has updates from %s, after last update %s", key, updateSeen, updatedAt)
return updateSeen
} else if !updatedAt.IsZero() {
klog.V(3).Infof("%s has updates from %s, before last update %s", key, updateSeen, updatedAt)
}

return updatedAt
}

func updateKey(i GitHubItem) string {
// https://github.com/kubernetes/minikube/pull/8431
parts := strings.Split(i.GetHTMLURL(), "/")
Expand Down