Better tracing

Not done yet, still need to add them to just about every other function
This commit is contained in:
Melody Becker 2024-11-06 16:57:44 +01:00
parent 83f47d17be
commit 529d106351
13 changed files with 148 additions and 22 deletions

View file

@ -5,6 +5,8 @@ import (
"strings"
"github.com/redis/go-redis/v9"
"github.com/rs/zerolog/log"
"gitlab.com/mstarongitlab/linstrom/util"
)
// various prefixes for accessing items in the cache (since it's a simple key-value store)
@ -24,6 +26,7 @@ var errCacheNotFound = errors.New("not found in cache")
// err contains an error describing why an account's id couldn't be found
// The most common one should be errCacheNotFound
func (s *Storage) cacheHandleToAccUid(handle string) (accId *string, err error) {
defer util.Untrace(util.Trace(&log.Logger))
// Where to put the data (in case it's found)
var target string
found, err := s.cache.Get(cacheUserHandleToIdPrefix+strings.TrimLeft(handle, "@"), &target)
@ -45,6 +48,7 @@ func (s *Storage) cacheHandleToAccUid(handle string) (accId *string, err error)
// err contains an error describing why an account's id couldn't be found
// The most common one should be errCacheNotFound
func (s *Storage) cacheLocalUsernameToAccUid(username string) (accId *string, err error) {
defer util.Untrace(util.Trace(&log.Logger))
// Where to put the data (in case it's found)
var target string
found, err := s.cache.Get(cacheLocalUsernameToIdPrefix+username, &target)
@ -62,6 +66,7 @@ func (s *Storage) cacheLocalUsernameToAccUid(username string) (accId *string, er
}
func (s *Storage) cachePkeyIdToAccId(pkeyId []byte) (accId *string, err error) {
defer util.Untrace(util.Trace(&log.Logger))
// Where to put the data (in case it's found)
var target string
found, err := s.cache.Get(cachePasskeyIdToAccIdPrefix+string(pkeyId), &target)
@ -83,6 +88,7 @@ func (s *Storage) cachePkeyIdToAccId(pkeyId []byte) (accId *string, err error) {
// err contains an error describing why an account couldn't be found
// The most common one should be errCacheNotFound
func (s *Storage) cacheAccIdToData(id string) (acc *Account, err error) {
defer util.Untrace(util.Trace(&log.Logger))
var target Account
found, err := s.cache.Get(cacheUserIdToAccPrefix+id, &target)
if !found {
@ -100,6 +106,7 @@ func (s *Storage) cacheAccIdToData(id string) (acc *Account, err error) {
// err contains an error describing why a note couldn't be found
// The most common one should be errCacheNotFound
func (s *Storage) cacheNoteIdToData(id string) (note *Note, err error) {
defer util.Untrace(util.Trace(&log.Logger))
target := Note{}
found, err := s.cache.Get(cacheNoteIdToNotePrefix+id, &target)
if !found {