Fix: load cards to remove old cards from db
This commit is contained in:
		| @@ -46,7 +46,6 @@ func (cm *CronManager) CleanupRooms() { | |||||||
| 			panic(r) | 			panic(r) | ||||||
| 		} | 		} | ||||||
| 	}() | 	}() | ||||||
|  |  | ||||||
| 	rooms, err := cm.repo.RoomList(ctx) | 	rooms, err := cm.repo.RoomList(ctx) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		cm.log.Error("failed to get rooms list", "err", err) | 		cm.log.Error("failed to get rooms list", "err", err) | ||||||
| @@ -55,7 +54,6 @@ func (cm *CronManager) CleanupRooms() { | |||||||
| 		} | 		} | ||||||
| 		return | 		return | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	for _, room := range rooms { | 	for _, room := range rooms { | ||||||
| 		players, err := cm.repo.PlayerListByRoom(ctx, room.ID) | 		players, err := cm.repo.PlayerListByRoom(ctx, room.ID) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| @@ -73,7 +71,6 @@ func (cm *CronManager) CleanupRooms() { | |||||||
| 			} | 			} | ||||||
| 			continue | 			continue | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		creatorInRoom := false | 		creatorInRoom := false | ||||||
| 		for _, player := range players { | 		for _, player := range players { | ||||||
| 			if player.Username == room.CreatorName { | 			if player.Username == room.CreatorName { | ||||||
| @@ -81,7 +78,6 @@ func (cm *CronManager) CleanupRooms() { | |||||||
| 				break | 				break | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		if !creatorInRoom { | 		if !creatorInRoom { | ||||||
| 			cm.log.Info("deleting room because creator left", "room_id", room.ID) | 			cm.log.Info("deleting room because creator left", "room_id", room.ID) | ||||||
| 			for _, player := range players { | 			for _, player := range players { | ||||||
| @@ -103,7 +99,6 @@ func (cm *CronManager) CleanupRooms() { | |||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	if err := tx.Commit(); err != nil { | 	if err := tx.Commit(); err != nil { | ||||||
| 		cm.log.Error("failed to commit transaction", "err", err) | 		cm.log.Error("failed to commit transaction", "err", err) | ||||||
| 	} | 	} | ||||||
| @@ -123,7 +118,6 @@ func (cm *CronManager) CleanupActions() { | |||||||
| 			panic(r) | 			panic(r) | ||||||
| 		} | 		} | ||||||
| 	}() | 	}() | ||||||
|  |  | ||||||
| 	if err := cm.repo.ActionDeleteOrphaned(ctx); err != nil { | 	if err := cm.repo.ActionDeleteOrphaned(ctx); err != nil { | ||||||
| 		cm.log.Error("failed to delete orphaned actions", "err", err) | 		cm.log.Error("failed to delete orphaned actions", "err", err) | ||||||
| 		if err := tx.Rollback(); err != nil { | 		if err := tx.Rollback(); err != nil { | ||||||
| @@ -131,7 +125,6 @@ func (cm *CronManager) CleanupActions() { | |||||||
| 		} | 		} | ||||||
| 		return | 		return | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	if err := tx.Commit(); err != nil { | 	if err := tx.Commit(); err != nil { | ||||||
| 		cm.log.Error("failed to commit transaction for actions cleanup", "err", err) | 		cm.log.Error("failed to commit transaction for actions cleanup", "err", err) | ||||||
| 	} | 	} | ||||||
| @@ -183,4 +176,3 @@ func (cm *CronManager) CleanupInactiveRooms() { | |||||||
| 		cm.log.Error("failed to commit transaction for inactive rooms cleanup", "err", err) | 		cm.log.Error("failed to commit transaction for inactive rooms cleanup", "err", err) | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -174,26 +174,6 @@ func joinTeam(ctx context.Context, role, team string) (*models.FullInfo, error) | |||||||
| 	return fi, nil | 	return fi, nil | ||||||
| } | } | ||||||
|  |  | ||||||
| // get all rooms |  | ||||||
| // func listRooms(allRooms bool) []*models.Room { |  | ||||||
| // 	cacheMap := memcache.GetAll() |  | ||||||
| // 	publicRooms := []*models.Room{} |  | ||||||
| // 	// no way to know if room is public until unmarshal -_-; |  | ||||||
| // 	for key, value := range cacheMap { |  | ||||||
| // 		if strings.HasPrefix(key, models.CacheRoomPrefix) { |  | ||||||
| // 			room := &models.Room{} |  | ||||||
| // 			if err := json.Unmarshal(value, &room); err != nil { |  | ||||||
| // 				log.Warn("failed to unmarshal room", "error", err) |  | ||||||
| // 				continue |  | ||||||
| // 			} |  | ||||||
| // 			if room.IsPublic || allRooms { |  | ||||||
| // 				publicRooms = append(publicRooms, room) |  | ||||||
| // 			} |  | ||||||
| // 		} |  | ||||||
| // 	} |  | ||||||
| // 	return publicRooms |  | ||||||
| // } |  | ||||||
|  |  | ||||||
| // get bots | // get bots | ||||||
| func listBots() []models.Player { | func listBots() []models.Player { | ||||||
| 	bots, err := repo.PlayerList(context.Background(), true) | 	bots, err := repo.PlayerList(context.Background(), true) | ||||||
| @@ -214,6 +194,9 @@ func notify(event, msg string) { | |||||||
| func loadCards(room *models.Room) { | func loadCards(room *models.Room) { | ||||||
| 	// remove old cards | 	// remove old cards | ||||||
| 	room.Cards = []models.WordCard{} | 	room.Cards = []models.WordCard{} | ||||||
|  | 	// try to delete old cards from db (in case players play another round) | ||||||
|  | 	// nolint: errcheck | ||||||
|  | 	repo.WordCardsDeleteByRoomID(context.Background(), room.ID) | ||||||
| 	// store it somewhere | 	// store it somewhere | ||||||
| 	wordMap := map[string]string{ | 	wordMap := map[string]string{ | ||||||
| 		"en": "assets/words/en_nouns.txt", | 		"en": "assets/words/en_nouns.txt", | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Grail Finder
					Grail Finder