public IReadOnlyList <DBClubInfoDto> GetClubs() { var value = _cache.Get <IReadOnlyList <DBClubInfoDto> >(ResourceCacheType.Clubs); if (value == null) { Logger.Information("Caching: Clubs"); Logger.Information("Caching..."); using (var db = GameDatabase.Open()) { var clubs = DbUtil.Find <ClubDto>(db).ToList(); var clubPlayers = DbUtil.Find <ClubPlayerDto>(db).ToList(); var dbClubInfoList = new List <DBClubInfoDto>(); foreach (var clubDto in clubs) { var clubInfo = new DBClubInfoDto { ClubDto = clubDto }; var dbPlayerInfoList = new List <ClubPlayerInfo>(); foreach (var playerInfoDto in clubPlayers.Where(p => p.ClubId == clubDto.Id)) { using (var dbC = AuthDatabase.Open()) { var account = DbUtil.Find <AccountDto>(dbC, statement => statement .Where($"{nameof(AccountDto.Id):C} = @{nameof(playerInfoDto.PlayerId)}") .WithParameters(new { playerInfoDto.PlayerId })) .FirstOrDefault(); dbPlayerInfoList.Add(new ClubPlayerInfo { AccountId = (ulong)playerInfoDto.PlayerId, State = (ClubState)playerInfoDto.State, Rank = (ClubRank)playerInfoDto.Rank, Account = account }); } } clubInfo.PlayerDto = dbPlayerInfoList.ToArray(); dbClubInfoList.Add(clubInfo); } value = dbClubInfoList.ToArray(); } _cache.Set(ResourceCacheType.Clubs, value); } return(value); }
public IReadOnlyList <DBClubInfoDto> GetClubs() { var value = _cache.Get <IReadOnlyList <DBClubInfoDto> >(ResourceCacheType.Clubs); if (value == null) { Logger.Information("Caching..."); using (var db = GameDatabase.Open()) { var Clubs = db.Find <ClubDto>().ToList(); var ClubPlayers = db.Find <ClubPlayerDto>().ToList(); var DBClubInfoList = new List <DBClubInfoDto>(); foreach (var clubDto in Clubs) { var ClubInfo = new DBClubInfoDto(); ClubInfo.ClubDto = clubDto; var DBPlayerInfoList = new List <ClubPlayerInfo>(); foreach (var playerInfoDto in ClubPlayers.Where(p => p.ClubId == clubDto.Id)) { AccountDto account; using (var dbC = AuthDatabase.Open()) { account = (dbC.Find <AccountDto>(statement => statement .Where($"{nameof(AccountDto.Id):C} = @{nameof(playerInfoDto.PlayerId)}") .WithParameters(new { playerInfoDto.PlayerId }))) .FirstOrDefault(); DBPlayerInfoList.Add(new ClubPlayerInfo() { AccountId = (ulong)playerInfoDto.PlayerId, State = (ClubState)playerInfoDto.State, IsMod = playerInfoDto.IsMod, account = account, }); } } ClubInfo.PlayerDto = DBPlayerInfoList.ToArray(); DBClubInfoList.Add(ClubInfo); } value = DBClubInfoList.ToArray(); } _cache.Set(ResourceCacheType.Clubs, value); } return(value); }