Skip to content

Commit 0e2972d

Browse files
committed
cache ladders
1 parent 5e6dc22 commit 0e2972d

1 file changed

Lines changed: 17 additions & 3 deletions

File tree

ZkData/Ef/WHR/WholeHistoryRating.cs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,23 @@ public void ProcessBattle(SpringBattle battle)
106106
}
107107
}
108108

109+
private List<Account> laddersCache = new List<Account>();
110+
109111
public List<Account> GetTopPlayers(int count)
110112
{
111-
ZkDataContext db = new ZkDataContext();
112-
List<int> retIDs = topPlayers.Take(count).ToList();
113-
return db.Accounts.Where(a => retIDs.Contains(a.AccountID)).OrderByDescending(x => x.AccountRatings.Where(r => r.RatingCategory == category).Select(r => r.Elo).DefaultIfEmpty(-1).FirstOrDefault()).ToList();
113+
if (count > 200)
114+
{
115+
ZkDataContext db = new ZkDataContext();
116+
laddersCache = db.Accounts.OrderByDescending(x => x.AccountRatings.Where(r => r.RatingCategory == category).Select(r => r.Elo).DefaultIfEmpty(-1).FirstOrDefault()).Take(count).ToList();
117+
}
118+
if (laddersCache.Count < count)
119+
{
120+
121+
ZkDataContext db = new ZkDataContext();
122+
List<int> retIDs = topPlayers.Take(count).ToList();
123+
laddersCache = db.Accounts.Where(a => retIDs.Contains(a.AccountID)).OrderByDescending(x => x.AccountRatings.Where(r => r.RatingCategory == category).Select(r => r.Elo).DefaultIfEmpty(-1).FirstOrDefault()).ToList();
124+
}
125+
return laddersCache.Take(count).ToList();
114126
}
115127

116128
public List<Account> GetTopPlayers(int count, Func<Account, bool> selector)
@@ -375,6 +387,7 @@ private void UpdateRankings(IEnumerable<Player> players)
375387
}
376388
}
377389
topPlayers = newTopPlayers;
390+
laddersCache = new List<Account>();
378391
Trace.TraceInformation("WHR " + category +" Ladders updated with " + topPlayers.Count + "/" + this.players.Count + " entries, max uncertainty selected: " + DynamicMaxUncertainty);
379392

380393
var playerIds = players.Select(x => x.id).ToList();
@@ -387,6 +400,7 @@ private void UpdateRankings(IEnumerable<Player> players)
387400
}
388401

389402
//check for topX updates
403+
GetTopPlayers(GlobalConst.LadderSize);
390404
foreach (var listener in topPlayersUpdateListeners)
391405
{
392406
if (matched < listener.Value)

0 commit comments

Comments
 (0)