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,7 @@ import (
"time"
"github.com/rs/zerolog/log"
"gitlab.com/mstarongitlab/linstrom/util"
"gorm.io/gorm"
)
@ -40,6 +41,7 @@ type Note struct {
}
func (s *Storage) FindNoteById(id string) (*Note, error) {
defer util.Untrace(util.Trace(&log.Logger))
note := &Note{}
cacheNote, err := s.cacheNoteIdToData(id)
switch err {
@ -68,6 +70,7 @@ func (s *Storage) FindNoteById(id string) (*Note, error) {
}
func (s *Storage) FindNotesByFuzzyContent(fuzzyContent string) ([]Note, error) {
defer util.Untrace(util.Trace(&log.Logger))
notes := []Note{}
// TODO: Figure out if cache can be used here too
err := s.db.Where("raw_content LIKE %?%", fuzzyContent).Find(notes).Error
@ -78,6 +81,7 @@ func (s *Storage) FindNotesByFuzzyContent(fuzzyContent string) ([]Note, error) {
}
func (s *Storage) FindNotesByAuthorHandle(handle string) ([]Note, error) {
defer util.Untrace(util.Trace(&log.Logger))
acc, err := s.FindAccountByFullHandle(handle)
if err != nil {
return nil, fmt.Errorf("account with handle %s not found: %w", handle, err)
@ -86,6 +90,7 @@ func (s *Storage) FindNotesByAuthorHandle(handle string) ([]Note, error) {
}
func (s *Storage) FindNotesByAuthorId(id string) ([]Note, error) {
defer util.Untrace(util.Trace(&log.Logger))
notes := []Note{}
err := s.db.Where("creator = ?", id).Find(notes).Error
switch err {
@ -99,6 +104,7 @@ func (s *Storage) FindNotesByAuthorId(id string) ([]Note, error) {
}
func (s *Storage) UpdateNote(note *Note) error {
defer util.Untrace(util.Trace(&log.Logger))
if note == nil || note.ID == "" {
return ErrInvalidData
}
@ -121,6 +127,7 @@ func (s *Storage) CreateNote() (*Note, error) {
}
func (s *Storage) DeleteNote(id string) {
defer util.Untrace(util.Trace(&log.Logger))
s.cache.Delete(cacheNoteIdToNotePrefix + id)
s.db.Delete(Note{ID: id})
}