Enha: model update
This commit is contained in:
@ -20,42 +20,43 @@ func createRoom(ctx context.Context, req *models.RoomReq) (*models.Room, error)
|
||||
}
|
||||
room := req.CreateRoom(creator)
|
||||
room.RoomLink = cfg.BaseURL + "/room-join?id=" + room.ID
|
||||
if err := saveRoom(room); err != nil {
|
||||
if err := repo.CreateRoom(ctx, room); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return room, nil
|
||||
}
|
||||
|
||||
func saveRoom(room *models.Room) error {
|
||||
key := models.CacheRoomPrefix + room.ID
|
||||
data, err := json.Marshal(room)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
memcache.Set(key, data)
|
||||
// do I need last action here? since room save is kind of an action on itself
|
||||
// time.Now().Add(time.Hour).Sub(room.LastActionTS)
|
||||
anHour := int64(216000) // 60 * 60 * 60
|
||||
memcache.Expire(key, anHour)
|
||||
return nil
|
||||
}
|
||||
// // DEPRECATED
|
||||
// func saveRoom(room *models.Room) error {
|
||||
// key := models.CacheRoomPrefix + room.ID
|
||||
// data, err := json.Marshal(room)
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
// memcache.Set(key, data)
|
||||
// // do I need last action here? since room save is kind of an action on itself
|
||||
// // time.Now().Add(time.Hour).Sub(room.LastActionTS)
|
||||
// anHour := int64(216000) // 60 * 60 * 60
|
||||
// memcache.Expire(key, anHour)
|
||||
// return nil
|
||||
// }
|
||||
|
||||
func getRoomByID(roomID string) (*models.Room, error) {
|
||||
roomBytes, err := memcache.Get(models.CacheRoomPrefix + roomID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp := &models.Room{}
|
||||
if err := json.Unmarshal(roomBytes, &resp); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
// func getRoomByID(roomID string) (*models.Room, error) {
|
||||
// roomBytes, err := memcache.Get(models.CacheRoomPrefix + roomID)
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
// resp := &models.Room{}
|
||||
// if err := json.Unmarshal(roomBytes, &resp); err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
// return resp, nil
|
||||
// }
|
||||
|
||||
func removeRoom(roomID string) {
|
||||
key := models.CacheRoomPrefix + roomID
|
||||
memcache.RemoveKey(key)
|
||||
}
|
||||
// func removeRoom(roomID string) {
|
||||
// key := models.CacheRoomPrefix + roomID
|
||||
// memcache.RemoveKey(key)
|
||||
// }
|
||||
|
||||
// context
|
||||
|
||||
@ -76,17 +77,17 @@ func getStateByCtx(ctx context.Context) (*models.UserState, error) {
|
||||
// repo.CreateRoom()
|
||||
// }
|
||||
|
||||
func saveFullInfo(fi *models.FullInfo) error {
|
||||
// INFO: no transactions; so case is possible where first object is updated but the second is not
|
||||
if err := saveState(fi.State.Username, fi.State); err != nil {
|
||||
return err
|
||||
}
|
||||
log.Debug("saved user state", "state", fi.State)
|
||||
if err := saveRoom(fi.Room); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
// func saveFullInfo(fi *models.FullInfo) error {
|
||||
// // INFO: no transactions; so case is possible where first object is updated but the second is not
|
||||
// if err := saveState(fi.State.Username, fi.State); err != nil {
|
||||
// return err
|
||||
// }
|
||||
// log.Debug("saved user state", "state", fi.State)
|
||||
// if err := saveRoom(fi.Room); err != nil {
|
||||
// return err
|
||||
// }
|
||||
// return nil
|
||||
// }
|
||||
|
||||
func notifyBotIfNeeded(room *models.Room) {
|
||||
if botName := room.WhichBotToMove(); botName != "" {
|
||||
|
Reference in New Issue
Block a user