Skip to content

Commit

Permalink
chore: paginate 'depviz db dump'
Browse files Browse the repository at this point in the history
  • Loading branch information
moul committed Jul 22, 2019
1 parent 76904b7 commit 5cdbdcd
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions cli/cmd_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,25 @@ func (cmd *dbCommand) dbDumpCommand() *cobra.Command {
}

func dbDump(opts *dbOptions) error {
issues := []*issues.Issue{}
if err := db.Find(&issues).Error; err != nil {
return err
query := db.Model(issues.Issue{}).Order("created_at")
perPage := 100
var allIssues []*issues.Issue
for page := 0; ; page++ {
var newIssues []*issues.Issue
if err := query.Limit(perPage).Offset(perPage * page).Find(&newIssues).Error; err != nil {
return err
}
allIssues = append(allIssues, newIssues...)
if len(newIssues) < perPage {
break
}
}

for _, issue := range issues {
for _, issue := range allIssues {
issue.PostLoad()
}

out, err := json.MarshalIndent(issues, "", " ")
out, err := json.MarshalIndent(allIssues, "", " ")
if err != nil {
return err
}
Expand Down

0 comments on commit 5cdbdcd

Please sign in to comment.