From 323582f51f1fa74fb442389bf149d53478407b85 Mon Sep 17 00:00:00 2001 From: Manfred Touron Date: Sun, 23 Sep 2018 14:04:50 +0200 Subject: [PATCH] feat: pull caching (#60) --- cmd_pull.go | 7 +++++++ issue.go | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/cmd_pull.go b/cmd_pull.go index bcc14cd14..fffb0886c 100644 --- a/cmd_pull.go +++ b/cmd_pull.go @@ -79,9 +79,16 @@ func pull(opts *pullOptions) error { client := github.NewClient(tc) go func(repo Repo) { + total := 0 defer wg.Done() opts := &github.IssueListByRepoOptions{State: "all"} + + var lastEntry Issue + if err := db.Where("repo_url = ?", repo.Canonical()).Order("updated_at desc").First(&lastEntry).Error; err == nil { + opts.Since = lastEntry.UpdatedAt + } + for { issues, resp, err := client.Issues.ListByRepo(ctx, repo.Namespace(), repo.Project(), opts) if err != nil { diff --git a/issue.go b/issue.go index 697296d0f..6301b2ffe 100644 --- a/issue.go +++ b/issue.go @@ -9,6 +9,7 @@ import ( "regexp" "strconv" "strings" + "time" "github.com/awalterschulze/gographviz" "github.com/google/go-github/github" @@ -44,6 +45,8 @@ type Issue struct { Errors []error `json:"-" gorm:"-"` // mapping + CreatedAt time.Time + UpdatedAt time.Time Number int Title string State string @@ -72,6 +75,8 @@ func FromGitHubIssue(input *github.Issue) *Issue { } parts := strings.Split(*input.HTMLURL, "/") issue := &Issue{ + CreatedAt: *input.CreatedAt, + UpdatedAt: *input.UpdatedAt, Provider: GitHubProvider, GitHub: input, Number: *input.Number,