mirror of
https://github.com/RaidMax/IW4M-Admin.git
synced 2025-06-10 15:20:48 -05:00
fix memory leak issue related to AddDbContext not working as expected
This commit is contained in:
@ -2,7 +2,6 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using SharedLibraryCore;
|
||||
using IW4MAdmin.Plugins.Stats.Models;
|
||||
using System.Collections.Generic;
|
||||
@ -19,7 +18,8 @@ namespace IW4MAdmin.Plugins.Stats.Commands
|
||||
private readonly IDatabaseContextFactory _contextFactory;
|
||||
private readonly CommandConfiguration _config;
|
||||
|
||||
public MostKillsCommand(CommandConfiguration config, ITranslationLookup translationLookup, IDatabaseContextFactory contextFactory) : base(config, translationLookup)
|
||||
public MostKillsCommand(CommandConfiguration config, ITranslationLookup translationLookup,
|
||||
IDatabaseContextFactory contextFactory) : base(config, translationLookup)
|
||||
{
|
||||
Name = "mostkills";
|
||||
Description = translationLookup["PLUGINS_STATS_COMMANDS_MOSTKILLS_DESC"];
|
||||
@ -32,7 +32,8 @@ namespace IW4MAdmin.Plugins.Stats.Commands
|
||||
|
||||
public override async Task ExecuteAsync(GameEvent E)
|
||||
{
|
||||
var mostKills = await GetMostKills(StatManager.GetIdForServer(E.Owner), Plugin.Config.Configuration(), _contextFactory, _translationLookup);
|
||||
var mostKills = await GetMostKills(StatManager.GetIdForServer(E.Owner), Plugin.Config.Configuration(),
|
||||
_contextFactory, _translationLookup);
|
||||
if (!E.Message.IsBroadcastCommand(_config.BroadcastCommandPrefix))
|
||||
{
|
||||
foreach (var stat in mostKills)
|
||||
@ -50,33 +51,33 @@ namespace IW4MAdmin.Plugins.Stats.Commands
|
||||
}
|
||||
}
|
||||
|
||||
public static async Task<IEnumerable<string>> GetMostKills(long? serverId, StatsConfiguration config, IDatabaseContextFactory contextFactory, ITranslationLookup translationLookup)
|
||||
public static async Task<IEnumerable<string>> GetMostKills(long? serverId, StatsConfiguration config,
|
||||
IDatabaseContextFactory contextFactory, ITranslationLookup translationLookup)
|
||||
{
|
||||
using (var ctx = contextFactory.CreateContext(enableTracking: false))
|
||||
{
|
||||
var dayInPast = DateTime.UtcNow.AddDays(-config.MostKillsMaxInactivityDays);
|
||||
await using var ctx = contextFactory.CreateContext(enableTracking: false);
|
||||
var dayInPast = DateTime.UtcNow.AddDays(-config.MostKillsMaxInactivityDays);
|
||||
|
||||
var iqStats = (from stats in ctx.Set<EFClientStatistics>()
|
||||
join client in ctx.Clients
|
||||
on stats.ClientId equals client.ClientId
|
||||
join alias in ctx.Aliases
|
||||
on client.CurrentAliasId equals alias.AliasId
|
||||
where stats.ServerId == serverId
|
||||
where client.Level != EFClient.Permission.Banned
|
||||
where client.LastConnection >= dayInPast
|
||||
orderby stats.Kills descending
|
||||
select new
|
||||
{
|
||||
alias.Name,
|
||||
stats.Kills
|
||||
})
|
||||
.Take(config.MostKillsClientLimit);
|
||||
var iqStats = (from stats in ctx.Set<EFClientStatistics>()
|
||||
join client in ctx.Clients
|
||||
on stats.ClientId equals client.ClientId
|
||||
join alias in ctx.Aliases
|
||||
on client.CurrentAliasId equals alias.AliasId
|
||||
where stats.ServerId == serverId
|
||||
where client.Level != EFClient.Permission.Banned
|
||||
where client.LastConnection >= dayInPast
|
||||
orderby stats.Kills descending
|
||||
select new
|
||||
{
|
||||
alias.Name,
|
||||
stats.Kills
|
||||
})
|
||||
.Take(config.MostKillsClientLimit);
|
||||
|
||||
var iqList = await iqStats.ToListAsync();
|
||||
var iqList = await iqStats.ToListAsync();
|
||||
|
||||
return iqList.Select((stats, index) => translationLookup["PLUGINS_STATS_COMMANDS_MOSTKILLS_FORMAT"].FormatExt(index + 1, stats.Name, stats.Kills))
|
||||
.Prepend(Utilities.CurrentLocalization.LocalizationIndex["PLUGINS_STATS_COMMANDS_MOSTKILLS_HEADER"]);
|
||||
}
|
||||
return iqList.Select((stats, index) => translationLookup["PLUGINS_STATS_COMMANDS_MOSTKILLS_FORMAT"]
|
||||
.FormatExt(index + 1, stats.Name, stats.Kills))
|
||||
.Prepend(Utilities.CurrentLocalization.LocalizationIndex["PLUGINS_STATS_COMMANDS_MOSTKILLS_HEADER"]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user