1
0

efficiently update bard convo hash

This commit is contained in:
Antonio 2023-06-13 00:47:24 +08:00
parent 0c2a0e72b3
commit d04d8f94dc
2 changed files with 16 additions and 8 deletions

View File

@ -6,14 +6,6 @@ type BardCache struct {
Bards map[string]*Bard
}
func GarbageCollectCache(cache *BardCache) {
for k, v := range cache.Bards {
if time.Since(v.LastInteractionTime) > time.Minute*5 {
delete(cache.Bards, k)
}
}
}
var cache *BardCache
func init() {

View File

@ -3,6 +3,7 @@ package bard
import (
"crypto/md5"
"encoding/hex"
"time"
)
func HashConversation(conversation []string) string {
@ -12,3 +13,18 @@ func HashConversation(conversation []string) string {
}
return hex.EncodeToString(hash.Sum(nil))
}
func GarbageCollectCache(cache *BardCache) {
for k, v := range cache.Bards {
if time.Since(v.LastInteractionTime) > time.Minute*5 {
delete(cache.Bards, k)
}
}
}
func UpdateBardHash(old_hash, hash string) {
if _, ok := cache.Bards[old_hash]; ok {
cache.Bards[hash] = cache.Bards[old_hash]
delete(cache.Bards, old_hash)
}
}