Skip to content
This repository was archived by the owner on Mar 27, 2024. It is now read-only.

Commit f648795

Browse files
author
Firas Qutishat
authored
Merge pull request #2383 from fqutishat/update
fix: batch write
2 parents 2548dfd + 97fba5d commit f648795

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

pkg/storage/formattedstore/batchwrite.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,9 @@ func newPendingBatch(provider batchProvider, formatter Formatter) *pendingBatch
164164
}
165165

166166
func (p *pendingBatch) put(addBatch *batch) error {
167+
p.mutex.Lock()
168+
defer p.mutex.Unlock()
169+
167170
p.size++
168171

169172
formattedValue, err := p.formatter.FormatPair(addBatch.keyID, addBatch.value)
@@ -176,35 +179,30 @@ func (p *pendingBatch) put(addBatch *batch) error {
176179
return err
177180
}
178181

179-
p.mutex.Lock()
180-
181182
p.values = append(p.values, models.VaultOperation{
182183
Operation: models.UpsertDocumentVaultOperation,
183184
EncryptedDocument: *encryptedDocument,
184185
})
185186

186-
p.mutex.Unlock()
187-
188187
return nil
189188
}
190189

191190
func (p *pendingBatch) delete(addBatch *batch) error {
191+
p.mutex.Lock()
192+
defer p.mutex.Unlock()
193+
192194
p.size++
193195

194196
id, err := p.formatter.GenerateEDVDocumentID(addBatch.keyID)
195197
if err != nil {
196198
return err
197199
}
198200

199-
p.mutex.Lock()
200-
201201
p.values = append(p.values, models.VaultOperation{
202202
Operation: models.DeleteDocumentVaultOperation,
203203
DocumentID: id,
204204
})
205205

206-
p.mutex.Unlock()
207-
208206
return nil
209207
}
210208

0 commit comments

Comments
 (0)