Skip to content
This repository has been archived by the owner on Nov 16, 2023. It is now read-only.

Commit

Permalink
efficiently update bard convo hash
Browse files Browse the repository at this point in the history
  • Loading branch information
Antonio committed Jun 12, 2023
1 parent 0c2a0e7 commit d04d8f9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
8 changes: 0 additions & 8 deletions internal/bard/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
16 changes: 16 additions & 0 deletions internal/bard/utilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package bard
import (
"crypto/md5"
"encoding/hex"
"time"
)

func HashConversation(conversation []string) string {
Expand All @@ -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)
}
}

0 comments on commit d04d8f9

Please sign in to comment.