velodrome/transform/fetcher.go
func (f *Fetcher) fetchRecentEventsAndComments(db *gorm.DB) error {
	glog.Infof("Fetching issue-events with id bigger than %s", f.lastEvent)
	glog.Infof("Fetching comments with id bigger than %s", f.lastComment)

	eventRows, err := db.
		Model(sql.IssueEvent{}).
		Where("repository = ?", f.repository).
		Where("event_created_at > ?", f.lastEvent).
		Order("event_created_at asc").
		Rows()
	if err != nil {
		return fmt.Errorf("Failed to query events from database: %s", err)
	}

	commentRows, err := db.
		Model(sql.Comment{}).
		Where("repository = ?", f.repository).
		Where("comment_created_at > ?", f.lastComment).
		Order("comment_created_at asc").
		Rows()
	if err != nil {
		return fmt.Errorf("Failed to query comments from database: %s", err)
	}

	count := 0
	comment := &sql.Comment{}
	if commentRows.Next() {
		db.ScanRows(commentRows, comment)
	} else {
		comment = nil
	}
	event := &sql.IssueEvent{}
	if eventRows.Next() {
		db.ScanRows(eventRows, event)
	} else {
		event = nil
	}

	for event != nil || comment != nil {
		if event == nil || (comment != nil && comment.CommentCreatedAt.Before(event.EventCreatedAt)) {
			f.EventsCommentsChannel <- *comment
			f.lastComment = comment.CommentCreatedAt
			if commentRows.Next() {
				db.ScanRows(commentRows, comment)
			} else {
				comment = nil
			}
		} else {
			f.EventsCommentsChannel <- *event
			f.lastEvent = event.EventCreatedAt
			if eventRows.Next() {
				db.ScanRows(eventRows, event)
			} else {
				event = nil
			}
		}
		count++
	}

	glog.Infof("Found and pushed %d new events/comments", count)

	return nil
}
func (f *Fetcher) fetchRecentEventsAndComments(db *gorm.DB) error {
	glog.Infof("Fetching issue-events with id bigger than %s", f.lastEvent)
	glog.Infof("Fetching comments with id bigger than %s", f.lastComment)

	eventRows, err := db.
		Model(sql.IssueEvent{}).
		Where("repository = ?", f.repository).
		Where("event_created_at > ?", f.lastEvent).
		Order("event_created_at asc").
		Rows()
	if err != nil {
		return fmt.Errorf("Failed to query events from database: %s", err)
	}

	commentRows, err := db.
		Model(sql.Comment{}).
		Where("repository = ?", f.repository).
		Where("comment_created_at > ?", f.lastComment).
		Order("comment_created_at asc").
		Rows()
	if err != nil {
		return fmt.Errorf("Failed to query comments from database: %s", err)
	}

	count := 0
	comment := &sql.Comment{}
	if commentRows.Next() {
		db.ScanRows(commentRows, comment)
	} else {
		comment = nil
	}
	event := &sql.IssueEvent{}
	if eventRows.Next() {
		db.ScanRows(eventRows, event)
	} else {
		event = nil
	}

	for event != nil || comment != nil {
		if event == nil || (comment != nil && comment.CommentCreatedAt.Before(event.EventCreatedAt)) {
			f.EventsCommentsChannel <- *comment
			f.lastComment = comment.CommentCreatedAt
			if commentRows.Next() {
				db.ScanRows(commentRows, comment)
			} else {
				comment = nil
			}
		} else {
			f.EventsCommentsChannel <- *event
			f.lastEvent = event.EventCreatedAt
			if eventRows.Next() {
				db.ScanRows(eventRows, event)
			} else {
				event = nil
			}
		}
		count++
	}

	glog.Infof("Found and pushed %d new events/comments", count)

	return nil
}
func ( f * Fetcher ) fetchRecentEventsAndComments ( db * gorm . DB ) error { glog . Infof ( " " , f . lastEvent ) glog . Infof ( " " , f . lastComment ) eventRows , err := db . Model ( sql . IssueEvent { } ) . Where ( " " , f . repository ) . Where ( " " , f . lastEvent ) . Order ( " " ) . Rows ( ) if err != nil { return fmt . Errorf ( " " , err ) } commentRows , err := db . Model ( sql . Comment { } ) . Where ( " " , f . repository ) . Where ( " " , f . lastComment ) . Order ( " " ) . Rows ( ) if err != nil { return fmt . Errorf ( " " , err ) } count := 0 comment := & sql . Comment { } if commentRows . Next ( ) { db . ScanRows ( commentRows , comment ) } else { comment = nil } event := & sql . IssueEvent { } if eventRows . Next ( ) { db . ScanRows ( eventRows , event ) } else { event = nil } for event != nil || comment != nil { if event == nil || ( comment != nil && comment . CommentCreatedAt . Before ( event . EventCreatedAt ) ) { f . EventsCommentsChannel <- * comment f . lastComment = comment . CommentCreatedAt if commentRows . Next ( ) { db . ScanRows ( commentRows , comment ) } else { comment = nil } } else { f . EventsCommentsChannel <- * event f . lastEvent = event . EventCreatedAt if eventRows . Next ( ) { db . ScanRows ( eventRows , event ) } else { event = nil } } count ++ } glog . Infof ( " " , count ) return nil }
// fetchRecentEventsAndComments retrieves events from DB, but only fetches events created since last call
fetchRecentEventsAndComments retrieves events from DB but only fetches events created since last call