From e4da93c569b737ab9f40ccf8c11a4e7dd2eebdba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Mur=C3=A9?= Date: Sat, 7 May 2022 00:04:33 +0200 Subject: [PATCH] feat: fast-path for PutMany, falling back to Put for single block call (#97) --- blockstore.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/blockstore.go b/blockstore.go index 61cb780..509e678 100644 --- a/blockstore.go +++ b/blockstore.go @@ -178,6 +178,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