From aa8ab34c0ee1f9c4cc4b53b791580756a20c0caf Mon Sep 17 00:00:00 2001 From: roger2hk Date: Wed, 31 Jul 2024 14:59:23 +0000 Subject: [PATCH] Fix sequence and integrate in MySQL storage implementation --- storage/mysql/mysql.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/storage/mysql/mysql.go b/storage/mysql/mysql.go index 2adc33c6..4386f4a4 100644 --- a/storage/mysql/mysql.go +++ b/storage/mysql/mysql.go @@ -259,11 +259,14 @@ func (s *Storage) sequenceBatch(ctx context.Context, entries []*tessera.Entry) e // integrate incorporates the provided entries into the log starting at fromSeq. func (s *Storage) integrate(ctx context.Context, tx *sql.Tx, fromSeq uint64, entries []*tessera.Entry) error { tb := storage.NewTreeBuilder(func(ctx context.Context, tileIDs []storage.TileID, treeSize uint64) ([]*api.HashTile, error) { - hashTiles := make([]*api.HashTile, len(tileIDs)) + hashTiles := make([]*api.HashTile, 0, len(tileIDs)) + if len(tileIDs) == 0 { + return hashTiles, nil + } // Build the SQL and args to fetch the hash tiles. var sql strings.Builder - args := make([]uint64, 0, len(tileIDs)*2) + args := make([]any, 0, len(tileIDs)*2) for i, id := range tileIDs { if i != 0 { sql.WriteString(" UNION ALL ") @@ -275,7 +278,7 @@ func (s *Storage) integrate(ctx context.Context, tx *sql.Tx, fromSeq uint64, ent args = append(args, id.Level, id.Index) } - rows, err := tx.QueryContext(ctx, sql.String(), args) + rows, err := tx.QueryContext(ctx, sql.String(), args...) if err != nil { return nil, fmt.Errorf("failed to query the hash tiles with SQL (%s): %w", sql.String(), err) }