From 652f3fb86ba5714488bf34bd4cdf0e7a69575edd Mon Sep 17 00:00:00 2001 From: RaidMax Date: Fri, 23 Aug 2019 19:11:36 -0500 Subject: [PATCH] Fix small issue with saving client kills multithreaded --- Plugins/Stats/Helpers/StatManager.cs | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/Plugins/Stats/Helpers/StatManager.cs b/Plugins/Stats/Helpers/StatManager.cs index b165651f2..34e57de5c 100644 --- a/Plugins/Stats/Helpers/StatManager.cs +++ b/Plugins/Stats/Helpers/StatManager.cs @@ -556,18 +556,21 @@ namespace IW4MAdmin.Plugins.Stats.Helpers { if (Plugin.Config.Configuration().StoreClientKills) { - _hitCache.Add(hit); - - if (_hitCache.Count > Detection.MAX_TRACKED_HIT_COUNT) + lock (_hitCache) { + _hitCache.Add(hit); - using (var ctx = new DatabaseContext()) + if (_hitCache.Count > Detection.MAX_TRACKED_HIT_COUNT) { - ctx.AddRange(_hitCache); - await ctx.SaveChangesAsync(); - } - _hitCache.Clear(); + using (var ctx = new DatabaseContext()) + { + ctx.AddRange(_hitCache); + await ctx.SaveChangesAsync(); + } + + _hitCache.Clear(); + } } } @@ -578,7 +581,7 @@ namespace IW4MAdmin.Plugins.Stats.Helpers #if DEBUG if (clientDetection.TrackedHits.Count > 0) #else - if (clientDetection.TrackedHits.Count > Detection.MAX_TRACKED_HIT_COUNT) + if (clientDetection.TrackedHits.Count > Detection.MAX_TRACKED_HIT_COUNT) #endif { while (clientDetection.TrackedHits.Count > 0)