Skip to content

Commit

Permalink
historical_uptime: batch read rows
Browse files Browse the repository at this point in the history
Signed-off-by: bingyuyap <[email protected]>
  • Loading branch information
bingyuyap committed Apr 1, 2024
1 parent d5c6c3d commit 03ca108
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions fly/pkg/bigtable/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,19 +221,29 @@ func (db *BigtableDB) GetMessagesByRowKeys(ctx context.Context, rowKeys []string
var messages []*types.Message
var errors []error

err := table.ReadRows(ctx, bigtable.RowList(rowKeys), func(row bigtable.Row) bool {
message, err := db.bigtableRowToMessage(row)
if err != nil {
errors = append(errors, fmt.Errorf("failed to convert row to message: %v", err))
return true
const batchSize = 1000

for i := 0; i < len(rowKeys); i += batchSize {
end := i + batchSize
if end > len(rowKeys) {
end = len(rowKeys)
}
batchRowKeys := rowKeys[i:end]

err := table.ReadRows(ctx, bigtable.RowList(batchRowKeys), func(row bigtable.Row) bool {
message, err := db.bigtableRowToMessage(row)
if err != nil {
errors = append(errors, fmt.Errorf("failed to convert row to message: %v", err))
return true
}

messages = append(messages, message)
return true
})
messages = append(messages, message)
return true
})

if err != nil {
return nil, fmt.Errorf("failed to read messages: %v", err)
if err != nil {
return nil, fmt.Errorf("failed to read messages: %v", err)
}
}

if len(errors) > 0 {
Expand Down

0 comments on commit 03ca108

Please sign in to comment.