Skip to content

Commit b560503

Browse files
committed
fix: concurrent map error
1 parent da456f0 commit b560503

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

core/deduplicate.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
package core
22

3-
import "github.com/aFlyBird0/cubox-archiver/core/cubox"
3+
import (
4+
"sync"
5+
6+
"github.com/aFlyBird0/cubox-archiver/core/cubox"
7+
)
48

59
type Deduplicate struct {
10+
mu sync.RWMutex
611
keys map[string]struct{}
712
}
813

@@ -35,10 +40,15 @@ func NewDeduplicateWithKeysInitiator(initiator KeysInitiator) (*Deduplicate, err
3540

3641
func (d *Deduplicate) Remain(item *cubox.Item) bool {
3742
key := item.UserSearchEngineID
43+
d.mu.RLock()
3844
if _, ok := d.keys[key]; ok {
3945
return false
4046
}
47+
d.mu.RUnlock()
48+
49+
d.mu.Lock()
4150
d.keys[key] = struct{}{}
51+
d.mu.Unlock()
4252

4353
return true
4454
}

0 commit comments

Comments
 (0)