Skip to content

Commit 7ac68ad

Browse files
committed
use defer for batch.Close
1 parent 0e8e20a commit 7ac68ad

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

modules/indexer/code/bleve/bleve.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,10 +220,10 @@ func (b *Indexer) Index(ctx context.Context, repo *repo_model.Repository, sha st
220220
if err != nil {
221221
return err
222222
}
223+
defer gitBatch.Close()
223224

224225
for _, update := range changes.Updates {
225226
if err := b.addUpdate(ctx, gitBatch.Writer, gitBatch.Reader, sha, update, repo, batch); err != nil {
226-
gitBatch.Close()
227227
return err
228228
}
229229
}

modules/indexer/code/elasticsearch/elasticsearch.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,11 +212,11 @@ func (b *Indexer) Index(ctx context.Context, repo *repo_model.Repository, sha st
212212
if err != nil {
213213
return err
214214
}
215+
defer batch.Close()
215216

216217
for _, update := range changes.Updates {
217218
updateReqs, err := b.addUpdate(ctx, batch.Writer, batch.Reader, sha, update, repo)
218219
if err != nil {
219-
batch.Close()
220220
return err
221221
}
222222
if len(updateReqs) > 0 {

0 commit comments

Comments
 (0)