Opt: lazy init op

pull/21/head
zijiren233 2 years ago
parent 1a1a5f810a
commit b3221f108f

@ -28,6 +28,7 @@ var ServerCmd = &cobra.Command{
bootstrap.InitLog,
bootstrap.InitGinMode,
bootstrap.InitDatabase,
bootstrap.InitOp,
bootstrap.InitRtmp,
bootstrap.InitRoom,
)

@ -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
}

@ -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)

@ -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
}

@ -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

@ -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 {

Loading…
Cancel
Save