From 1b58d9b477bcb9c2c153b36f0e3d77ae380da000 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Mur=C3=A9?= Date: Fri, 25 Feb 2022 16:16:12 +0100 Subject: [PATCH] feat: fast-path for PutMany, falling back to Put for single block call --- blockstore.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/blockstore.go b/blockstore.go index 9572f76..eae76b2 100644 --- a/blockstore.go +++ b/blockstore.go @@ -180,6 +180,11 @@ func (bs *blockstore) Put(ctx context.Context, block blocks.Block) error { } func (bs *blockstore) PutMany(ctx context.Context, blocks []blocks.Block) error { + if len(blocks) == 1 { + // performance fast-path + return bs.Put(ctx, blocks[0]) + } + t, err := bs.datastore.Batch(ctx) if err != nil { return err