More stuff
This commit is contained in:
parent
71beed7eb3
commit
9a7e420c83
7 changed files with 63 additions and 33 deletions
12
storage/cache/cache.go
vendored
12
storage/cache/cache.go
vendored
|
@ -12,6 +12,7 @@ import (
|
|||
ristretto_store "github.com/eko/gocache/store/ristretto/v4"
|
||||
"github.com/redis/go-redis/v9"
|
||||
"github.com/rs/zerolog/log"
|
||||
"gitlab.com/mstarongitlab/linstrom/config"
|
||||
)
|
||||
|
||||
type Cache struct {
|
||||
|
@ -37,7 +38,9 @@ func NewCache(maxSize int64, redisUrl *string) (*Cache, error) {
|
|||
}
|
||||
ristrettoStore := ristretto_store.NewRistretto(
|
||||
ristrettoCache,
|
||||
store.WithExpiration(time.Second*10),
|
||||
store.WithExpiration(
|
||||
time.Second*time.Duration(config.GlobalConfig.Storage.MaxInMemoryCacheSize),
|
||||
),
|
||||
)
|
||||
|
||||
var cacheManager *cache.ChainCache[[]byte]
|
||||
|
@ -47,7 +50,12 @@ func NewCache(maxSize int64, redisUrl *string) (*Cache, error) {
|
|||
return nil, err
|
||||
}
|
||||
redisClient := redis.NewClient(opts)
|
||||
redisStore := redis_store.NewRedis(redisClient, store.WithExpiration(time.Minute))
|
||||
redisStore := redis_store.NewRedis(
|
||||
redisClient,
|
||||
store.WithExpiration(
|
||||
time.Second*time.Duration(*config.GlobalConfig.Storage.MaxRedisCacheTTL),
|
||||
),
|
||||
)
|
||||
cacheManager = cache.NewChain(
|
||||
cache.New[[]byte](ristrettoStore),
|
||||
cache.New[[]byte](redisStore),
|
||||
|
|
|
@ -4,3 +4,8 @@ package storage
|
|||
// Things like true deletion of soft deleted data after some time
|
||||
// Or removing inactive access tokens
|
||||
// All of this will be handled by goroutines
|
||||
|
||||
// TODO: Delete everything soft deleted and older than a month
|
||||
// TODO: Delete old tokens not in active use anymore
|
||||
// TODO: Start jobs where the last check-in was more than an hour ago
|
||||
//
|
||||
|
|
|
@ -107,7 +107,9 @@ func (s *Storage) UpdateNote(note *Note) error {
|
|||
}
|
||||
err = s.cache.Set(cacheNoteIdToNotePrefix+note.ID, note)
|
||||
if err != nil {
|
||||
log.Warn().Err(err).Msg("Failed to update note into cache. Cache and db might be out of sync, a force sync is recommended")
|
||||
log.Warn().
|
||||
Err(err).
|
||||
Msg("Failed to update note into cache. Cache and db might be out of sync, a force sync is recommended")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -121,13 +123,3 @@ func (s *Storage) DeleteNote(id string) {
|
|||
s.cache.Delete(cacheNoteIdToNotePrefix + id)
|
||||
s.db.Delete(Note{ID: id})
|
||||
}
|
||||
|
||||
// Try and find a note with a given ID
|
||||
func (store *Storage) FindNoteById(id string) (*Note, error) {
|
||||
note := Note{}
|
||||
res := store.db.First(¬e, id)
|
||||
if res.Error != nil {
|
||||
return nil, res.Error
|
||||
}
|
||||
return ¬e, nil
|
||||
}
|
||||
|
|
|
@ -7,7 +7,6 @@ package storage
|
|||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
"gitlab.com/mstarongitlab/linstrom/storage/cache"
|
||||
|
@ -47,8 +46,3 @@ func NewStorage(dbUrl string, cache *cache.Cache) (*Storage, error) {
|
|||
|
||||
return &Storage{db, cache}, nil
|
||||
}
|
||||
|
||||
// TODO: Placeholder. Update to proper implementation later. Including signature
|
||||
func (s *Storage) FindLocalAccount(handle string) (string, error) {
|
||||
return handle, nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue