cleanups to startup code and goroutine code

This commit is contained in:
2026-05-06 22:19:08 -06:00
parent 08a10a55dd
commit a2c2a1f750
9 changed files with 92 additions and 88 deletions
+6 -10
View File
@@ -1,6 +1,6 @@
/*
* Amsterdam Web Communities System
* Copyright (c) 2025 Erbosoft Metaverse Design Solutions, All Rights Reserved
* Copyright (c) 2025-2026 Erbosoft Metaverse Design Solutions, All Rights Reserved
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -44,17 +44,17 @@ func (d *TrieDictionary) Size() int {
// CheckWord returns true if a word is in the dictionary, false if not.
func (d *TrieDictionary) CheckWord(word string) bool {
d.mutex.Lock()
defer d.mutex.Unlock()
_, rc := d.trie.Find(strings.ToLower(word))
d.mutex.Unlock()
return rc
}
// AddWord adds a new word to the dictionary.
func (d *TrieDictionary) AddWord(word string) {
d.mutex.Lock()
defer d.mutex.Unlock()
d.trie.Add(strings.ToLower(word), true)
d.count++
d.mutex.Unlock()
}
// DelWord deletes a word from the dictionary.
@@ -89,12 +89,8 @@ func loadDict(d *TrieDictionary, words []byte) {
// LoadTrieDict creates a TrieDictionary from a byte array that represents a word list (one word per line).
func LoadTrieDict(words []byte) *TrieDictionary {
rc := TrieDictionary{
loaded: atomic.Bool{},
trie: trie.New(),
count: 0,
}
rc := new(TrieDictionary{loaded: atomic.Bool{}, trie: trie.New(), count: 0})
rc.loaded.Store(false)
go loadDict(&rc, words)
return &rc
go loadDict(rc, words)
return rc
}
+4 -6
View File
@@ -55,10 +55,8 @@ func SetupDicts() {
log.Errorf("failed to load external dictionary %s: %v", config.GlobalConfig.Posting.ExternalDictionary, err)
}
}
rw := spellingRewriter{
dict: NewCompositeDict(dicts),
}
rewriterRegistry[rw.Name()] = &rw
rw := new(spellingRewriter{dict: NewCompositeDict(dicts)})
rewriterRegistry[rw.Name()] = rw
}
// spellingRewriter is a rewriter that flags spelling errors.
@@ -89,10 +87,10 @@ func (rw *spellingRewriter) Rewrite(ctx context.Context, data string, svc rewrit
if rw.dict.CheckWord(data) {
return nil
}
return &markupData{
return new(markupData{
beginMarkup: defaultBeginError,
text: data,
endMarkup: defaultEndError,
rescan: false,
}
})
}