Skip to content

Commit dc56d79

Browse files
author
xieguanfeng
committed
fix load speed
1 parent 275f14d commit dc56d79

File tree

2 files changed

+9
-14
lines changed

2 files changed

+9
-14
lines changed

filter/ahocorasick.go

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -147,25 +147,19 @@ func (m *AcModel) buildFailPointers() {
147147

148148
func (m *AcModel) Listen(addChan, delChan <-chan string) {
149149
go func() {
150-
var words []string
151-
152150
for word := range addChan {
153-
words = append(words, word)
151+
m.addWord(word)
154152
if len(addChan) == 0 {
155-
m.AddWords(words...)
156-
word = word[:0]
153+
m.buildFailPointers()
157154
}
158155
}
159156
}()
160157

161158
go func() {
162-
var words []string
163-
164159
for word := range delChan {
165-
words = append(words, word)
160+
m.delWord(word)
166161
if len(delChan) == 0 {
167-
m.DelWords(words...)
168-
word = word[:0]
162+
m.buildFailPointers()
169163
}
170164
}
171165
}()

store/memory.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ package store
33
import (
44
"bufio"
55
"errors"
6-
"github.com/imroc/req/v3"
7-
cmap "github.com/orcaman/concurrent-map/v2"
86
"io"
97
"net/http"
108
"os"
9+
10+
"github.com/imroc/req/v3"
11+
cmap "github.com/orcaman/concurrent-map/v2"
1112
)
1213

1314
type MemoryModel struct {
@@ -19,8 +20,8 @@ type MemoryModel struct {
1920
func NewMemoryModel() *MemoryModel {
2021
return &MemoryModel{
2122
store: cmap.New[struct{}](),
22-
addChan: make(chan string),
23-
delChan: make(chan string),
23+
addChan: make(chan string, 1000),
24+
delChan: make(chan string, 1000),
2425
}
2526
}
2627

0 commit comments

Comments
 (0)