aboutsummaryrefslogtreecommitdiffstats
path: root/bridge/github/iterator.go
diff options
context:
space:
mode:
authorAmine Hilaly <hilalyamine@gmail.com>2019-04-27 00:15:02 +0100
committerAmine Hilaly <hilalyamine@gmail.com>2019-05-05 18:16:10 +0200
commit3bcaa35b5d25ca9e12389ab4bf78600ae5df8af8 (patch)
tree3c512c5324cce2fb1e9beefc810e2807936a0768 /bridge/github/iterator.go
parentc8ad4dbfd9511f4cfa748fa85c01fbca2edb348a (diff)
downloadgit-bug-3bcaa35b5d25ca9e12389ab4bf78600ae5df8af8.tar.gz
Integrate iterator with importer
Diffstat (limited to 'bridge/github/iterator.go')
-rw-r--r--bridge/github/iterator.go29
1 files changed, 15 insertions, 14 deletions
diff --git a/bridge/github/iterator.go b/bridge/github/iterator.go
index cb7c9760..9e1ff30e 100644
--- a/bridge/github/iterator.go
+++ b/bridge/github/iterator.go
@@ -46,6 +46,8 @@ type timelineIterator struct {
issueEdit indexer
commentEdit indexer
+
+ lastEndCursor githubv4.String // storing timeline end cursor for future use
}
type iterator struct {
@@ -81,9 +83,8 @@ func newIterator(conf core.Configuration, since time.Time) *iterator {
return &iterator{
since: since,
gc: buildClient(conf),
- capacity: 8,
- count: -1,
-
+ capacity: 10,
+ count: 0,
timeline: timelineIterator{
index: -1,
issueEdit: indexer{-1},
@@ -154,19 +155,20 @@ func (i *iterator) reverseTimelineEditNodes() {
}
}
-// Error .
+// Error return last encountered error
func (i *iterator) Error() error {
return i.err
}
-// Count .
+// Count return number of issues we iterated over
func (i *iterator) Count() int {
return i.count
}
+// Next issue
func (i *iterator) NextIssue() bool {
// we make the first move
- if i.count == -1 {
+ if i.count == 0 {
// init variables and goto queryIssue block
i.initTimelineQueryVariables()
@@ -181,11 +183,14 @@ func (i *iterator) NextIssue() bool {
return false
}
- // if we have more pages updates variables and query them
+ // if we have more issues, query them
i.timeline.variables["timelineAfter"] = (*githubv4.String)(nil)
i.timeline.variables["issueAfter"] = i.timeline.query.Repository.Issues.PageInfo.EndCursor
i.timeline.index = -1
+ // store cursor for future use
+ i.timeline.lastEndCursor = i.timeline.query.Repository.Issues.Nodes[0].Timeline.PageInfo.EndCursor
+
// query issue block
queryIssue:
if err := i.gc.Query(context.TODO(), &i.timeline.query, i.timeline.variables); err != nil {
@@ -224,6 +229,8 @@ func (i *iterator) NextTimeline() bool {
return false
}
+ i.timeline.lastEndCursor = i.timeline.query.Repository.Issues.Nodes[0].Timeline.PageInfo.EndCursor
+
// more timelines, query them
i.timeline.variables["timelineAfter"] = i.timeline.query.Repository.Issues.Nodes[0].Timeline.PageInfo.EndCursor
if err := i.gc.Query(context.TODO(), &i.timeline.query, i.timeline.variables); err != nil {
@@ -240,10 +247,6 @@ func (i *iterator) TimelineValue() timelineItem {
return i.timeline.query.Repository.Issues.Nodes[0].Timeline.Edges[i.timeline.index].Node
}
-func (i *iterator) timelineCursor() string {
- return ""
-}
-
func (i *iterator) NextIssueEdit() bool {
if i.err != nil {
return false
@@ -359,11 +362,9 @@ func (i *iterator) NextCommentEdit() bool {
return false
}
- // if there is more comment edits, query them
-
i.initCommentEditQueryVariables()
if i.timeline.index == 0 {
- i.commentEdit.variables["timelineAfter"] = i.timeline.query.Repository.Issues.Nodes[0].Timeline.PageInfo.EndCursor
+ i.commentEdit.variables["timelineAfter"] = i.timeline.lastEndCursor
} else {
i.commentEdit.variables["timelineAfter"] = i.timeline.query.Repository.Issues.Nodes[0].Timeline.Edges[i.timeline.index-1].Cursor
}