Skip to content

Commit 889c0eb

Browse files
committed
put db query in async task
1 parent 7903691 commit 889c0eb

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

ZkData/Ef/WHR/WholeHistoryRating.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,6 @@ public void ProcessBattle(SpringBattle battle)
101101
{
102102
Trace.TraceInformation(battlesRegistered + " battles registered for WHR " + category +", latest Battle: " + battle.SpringBattleID);
103103
UpdateRatings();
104-
using (var db = new ZkDataContext()) {
105-
db.SpringBattlePlayers.Where(p => p.SpringBattleID == battle.SpringBattleID && !p.IsSpectator && playerOldRatings.ContainsKey(p.AccountID)).ForEach(p => p.EloChange = playerRatings[p.AccountID].RealElo - playerOldRatings[p.AccountID].RealElo);
106-
db.SaveChanges();
107-
}
108-
losers.Concat(winners).ForEach(x => playerOldRatings[x] = playerRatings[x]);
109104
}
110105
}
111106
}
@@ -218,6 +213,16 @@ public void UpdateRatings()
218213
updateAction.Invoke();
219214
Trace.TraceInformation("WHR " + category +" Ratings updated in " + DateTime.Now.Subtract(start).TotalSeconds + " seconds, " + (GC.GetTotalMemory(false) / (1 << 20)) + "MiB total memory allocated");
220215
runningInitialization = false;
216+
217+
if (!latestBattle.Equals(lastUpdate))
218+
{
219+
using (var db = new ZkDataContext())
220+
{
221+
db.SpringBattlePlayers.Where(p => p.SpringBattleID == latestBattle.SpringBattleID && !p.IsSpectator && playerOldRatings.ContainsKey(p.AccountID)).ForEach(p => p.EloChange = playerRatings[p.AccountID].RealElo - playerOldRatings[p.AccountID].RealElo);
222+
db.SpringBattlePlayers.Where(p => p.SpringBattleID == latestBattle.SpringBattleID && !p.IsSpectator).ForEach(x => playerOldRatings[x.AccountID] = playerRatings[x.AccountID]);
223+
db.SaveChanges();
224+
}
225+
}
221226
}
222227
}
223228
catch (Exception ex)

0 commit comments

Comments
 (0)