Enha: removing memcache [WIP]

This commit is contained in:
Grail Finder
2025-07-02 09:17:11 +03:00
parent 86574bf69c
commit 95a55a8213
4 changed files with 43 additions and 21 deletions

View File

@ -158,15 +158,17 @@ func getAllNames() []string {
// can room exists without state? I think no
func getFullInfoByCtx(ctx context.Context) (*models.FullInfo, error) {
resp := &models.FullInfo{}
state, err := getStateByCtx(ctx)
if err != nil {
return nil, err
}
// state, err := getStateByCtx(ctx)
// if err != nil {
// return nil, err
// }
state, err := getPlayerByCtx(ctx)
resp.State = state
if state.RoomID == "" {
return resp, nil
}
room, err := getRoomByID(state.RoomID)
// room, err := getRoomByID(state.RoomID)
room, err := repo.GetRoomByID(ctx, state.RoomID)
if err != nil {
log.Warn("failed to find room despite knowing room_id;",
"room_id", state.RoomID)
@ -176,6 +178,15 @@ func getFullInfoByCtx(ctx context.Context) (*models.FullInfo, error) {
return resp, nil
}
func getPlayerByCtx(ctx context.Context) (*models.Player, error) {
username, ok := ctx.Value(models.CtxUsernameKey).(string)
if !ok {
log.Debug("no username in ctx")
return &models.Player{}, errors.New("no username in ctx")
}
return repo.GetPlayerByName(username)
}
// // DEPRECATED
// func leaveRole(fi *models.FullInfo) {
// fi.Room.RedTeam.Guessers = utils.RemoveFromSlice(fi.State.Username, fi.Room.RedTeam.Guessers)