diff --git a/cmd/server.go b/cmd/server.go index a1cc018..8bf946c 100644 --- a/cmd/server.go +++ b/cmd/server.go @@ -28,6 +28,7 @@ var ServerCmd = &cobra.Command{ bootstrap.InitLog, bootstrap.InitGinMode, bootstrap.InitDatabase, + bootstrap.InitOp, bootstrap.InitRtmp, bootstrap.InitRoom, ) diff --git a/internal/bootstrap/op.go b/internal/bootstrap/op.go new file mode 100644 index 0000000..3b8d762 --- /dev/null +++ b/internal/bootstrap/op.go @@ -0,0 +1,12 @@ +package bootstrap + +import ( + "context" + + "github.com/synctv-org/synctv/internal/op" +) + +func InitOp(ctx context.Context) error { + op.Init(4096) + return nil +} diff --git a/internal/op/movie.go b/internal/op/movie.go index 24f1b49..f6aab51 100644 --- a/internal/op/movie.go +++ b/internal/op/movie.go @@ -11,9 +11,7 @@ import ( "github.com/zijiren233/gencontainer/dllist" ) -var movieCache = gcache.New(2048). - LRU(). - Build() +var movieCache gcache.Cache func GetAllMoviesByRoomID(roomID uint) (*dllist.Dllist[*model.Movie], error) { i, err := movieCache.Get(roomID) diff --git a/internal/op/op.go b/internal/op/op.go new file mode 100644 index 0000000..0f349df --- /dev/null +++ b/internal/op/op.go @@ -0,0 +1,17 @@ +package op + +import ( + "github.com/bluele/gcache" +) + +func Init(size int) error { + userCache = gcache.New(size). + LRU(). + Build() + + movieCache = gcache.New(size). + LRU(). + Build() + + return nil +} diff --git a/internal/op/user.go b/internal/op/user.go index 351cd01..15c32ed 100644 --- a/internal/op/user.go +++ b/internal/op/user.go @@ -4,17 +4,12 @@ import ( "errors" "sync/atomic" - "github.com/bluele/gcache" "github.com/synctv-org/synctv/internal/db" "github.com/synctv-org/synctv/internal/model" "github.com/zijiren233/stream" "golang.org/x/crypto/bcrypt" ) -var userCache = gcache.New(2048). - LRU(). - Build() - type User struct { model.User version uint32 diff --git a/internal/op/users.go b/internal/op/users.go index 3360d8a..32b2835 100644 --- a/internal/op/users.go +++ b/internal/op/users.go @@ -3,6 +3,7 @@ package op import ( "time" + "github.com/bluele/gcache" "github.com/synctv-org/synctv/internal/db" "github.com/synctv-org/synctv/internal/model" "github.com/zijiren233/stream" @@ -10,6 +11,8 @@ import ( "gorm.io/gorm/clause" ) +var userCache gcache.Cache + func GetUserById(id uint) (*User, error) { i, err := userCache.Get(id) if err == nil {