Changed how StorePanakoPrints checks for dupes
This commit is contained in:
parent
a2e5cdf695
commit
3655b1bb27
|
@ -219,33 +219,14 @@ func (s *SpecializedPanakoStore) StorePanakoPrint(record panako.StoreRecord) {
|
|||
}
|
||||
}
|
||||
|
||||
//StorePanakoPrints this does not check for existence
|
||||
func (s *SpecializedPanakoStore) StorePanakoPrints(records []panako.StoreRecord) {
|
||||
//TODO: dupe prints might be stored this way if given at the same time
|
||||
printsToStore := make([][2][]byte, 0, len(records))
|
||||
s.mutex.RLock()
|
||||
for _, record := range records {
|
||||
key, value := getKeyValue(record, s.useCompactHashes)
|
||||
err := s.bpt.DoFind(key, func(k, v []byte) error {
|
||||
if bytes.Compare(value, v) == 0 {
|
||||
return errors.New("value exists")
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
if err == nil {
|
||||
printsToStore = append(printsToStore, [2][]byte{
|
||||
key,
|
||||
value,
|
||||
})
|
||||
}
|
||||
}
|
||||
s.mutex.RUnlock()
|
||||
|
||||
if len(printsToStore) > 0 {
|
||||
if len(records) > 0 {
|
||||
s.mutex.Lock()
|
||||
defer s.mutex.Unlock()
|
||||
for _, v := range printsToStore {
|
||||
err := s.bpt.Add(v[0], v[1])
|
||||
for _, record := range records {
|
||||
key, value := getKeyValue(record, s.useCompactHashes)
|
||||
err := s.bpt.Add(key, value)
|
||||
if err != nil {
|
||||
log.Panic(err)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue