Fixed a few bugs

- Fixed a seg fault bug when cancelling a scan or query when no results are available yet
- Reduce the size of each page to return so that progress indicators work
This commit is contained in:
Leon Mika 2022-10-20 09:51:53 +11:00
parent 7eb4ea7222
commit fc75070a4f
2 changed files with 18 additions and 10 deletions

View file

@ -277,6 +277,10 @@ func (c *TableReadController) handleResultSetFromJobResult(filter string, pushba
var partialResultsErr models.PartialResultsError var partialResultsErr models.PartialResultsError
if errors.As(err, &partialResultsErr) { if errors.As(err, &partialResultsErr) {
if newResultSet == nil {
return events.StatusMsg("Operation cancelled")
}
return events.Confirm(applyToN("View the ", len(newResultSet.Items()), "item", "items", " returned so far? "), func(yes bool) tea.Msg { return events.Confirm(applyToN("View the ", len(newResultSet.Items()), "item", "items", " returned so far? "), func(yes bool) tea.Msg {
if yes { if yes {
return c.setResultSetAndFilter(newResultSet, filter, pushbackStack, op) return c.setResultSetAndFilter(newResultSet, filter, pushbackStack, op)

View file

@ -115,7 +115,9 @@ func (p *Provider) ScanItems(ctx context.Context, tableName string, filterExpr *
input.ExpressionAttributeValues = filterExpr.Values() input.ExpressionAttributeValues = filterExpr.Values()
} }
paginator := dynamodb.NewScanPaginator(p.client, input) paginator := dynamodb.NewScanPaginator(p.client, input, func(opt *dynamodb.ScanPaginatorOptions) {
opt.Limit = 100
})
items := make([]models.Item, 0) items := make([]models.Item, 0)
@ -136,13 +138,13 @@ outer:
if len(items) >= maxItems { if len(items) >= maxItems {
break outer break outer
} }
}
if time.Now().After(nextUpdate) { if time.Now().After(nextUpdate) {
jobs.PostUpdate(ctx, fmt.Sprintf("found %d items", len(items))) jobs.PostUpdate(ctx, fmt.Sprintf("found %d items", len(items)))
nextUpdate = time.Now().Add(1 * time.Second) nextUpdate = time.Now().Add(1 * time.Second)
} }
} }
}
return items, nil return items, nil
} }
@ -159,7 +161,9 @@ func (p *Provider) QueryItems(ctx context.Context, tableName string, filterExpr
input.ExpressionAttributeValues = filterExpr.Values() input.ExpressionAttributeValues = filterExpr.Values()
} }
paginator := dynamodb.NewQueryPaginator(p.client, input) paginator := dynamodb.NewQueryPaginator(p.client, input, func(opt *dynamodb.QueryPaginatorOptions) {
opt.Limit = 100
})
items := make([]models.Item, 0) items := make([]models.Item, 0)
@ -180,13 +184,13 @@ outer:
if len(items) >= maxItems { if len(items) >= maxItems {
break outer break outer
} }
}
if time.Now().After(nextUpdate) { if time.Now().After(nextUpdate) {
jobs.PostUpdate(ctx, fmt.Sprintf("found %d items", len(items))) jobs.PostUpdate(ctx, fmt.Sprintf("found %d items", len(items)))
nextUpdate = time.Now().Add(1 * time.Second) nextUpdate = time.Now().Add(1 * time.Second)
} }
} }
}
return items, nil return items, nil
} }