From 3539101a402a542f36ffbedc6c2a3a5dcd51b46b Mon Sep 17 00:00:00 2001 From: RaidMax Date: Fri, 28 Jan 2022 14:33:08 -0600 Subject: [PATCH] webfront profile loading optimizations --- .../PostgresqlDatabaseContext.cs | 4 +-- Plugins/Stats/Plugin.cs | 10 ------ SharedLibraryCore/Services/PenaltyService.cs | 31 ++++++++++++++----- 3 files changed, 26 insertions(+), 19 deletions(-) diff --git a/Data/MigrationContext/PostgresqlDatabaseContext.cs b/Data/MigrationContext/PostgresqlDatabaseContext.cs index d3df902e2..cccd89155 100644 --- a/Data/MigrationContext/PostgresqlDatabaseContext.cs +++ b/Data/MigrationContext/PostgresqlDatabaseContext.cs @@ -25,10 +25,10 @@ namespace Data.MigrationContext { optionsBuilder.UseNpgsql( "Host=127.0.0.1;Database=IW4MAdmin_Migration;Username=postgres;Password=password;", - options => options.SetPostgresVersion(new Version("9.4"))) + options => options.SetPostgresVersion(new Version("12.9"))) .EnableDetailedErrors(true) .EnableSensitiveDataLogging(true); } } } -} \ No newline at end of file +} diff --git a/Plugins/Stats/Plugin.cs b/Plugins/Stats/Plugin.cs index 2266e3822..9e1f9992f 100644 --- a/Plugins/Stats/Plugin.cs +++ b/Plugins/Stats/Plugin.cs @@ -11,7 +11,6 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Data.Abstractions; -using Data.Models.Client; using Data.Models.Client.Stats; using Data.Models.Server; using Microsoft.Extensions.Logging; @@ -195,7 +194,6 @@ namespace IW4MAdmin.Plugins.Stats int messageCount = 0; await using var ctx = _databaseContextFactory.CreateContext(enableTracking: false); clientStats = await ctx.Set().Where(c => c.ClientId == request.ClientId).ToListAsync(); - messageCount = await ctx.Set().CountAsync(_message => _message.ClientId == request.ClientId); int kills = clientStats.Sum(c => c.Kills); int deaths = clientStats.Sum(c => c.Deaths); @@ -254,14 +252,6 @@ namespace IW4MAdmin.Plugins.Stats Column = 0, Order = 5, Type = MetaType.Information - }, - new InformationResponse() - { - Key = Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_PROFILE_MESSAGES"], - Value = messageCount.ToString("#,##0", new System.Globalization.CultureInfo(Utilities.CurrentLocalization.LocalizationName)), - Column = 1, - Order = 4, - Type = MetaType.Information } }; } diff --git a/SharedLibraryCore/Services/PenaltyService.cs b/SharedLibraryCore/Services/PenaltyService.cs index 136ca0fef..e8dfd2826 100644 --- a/SharedLibraryCore/Services/PenaltyService.cs +++ b/SharedLibraryCore/Services/PenaltyService.cs @@ -181,19 +181,36 @@ namespace SharedLibraryCore.Services var aliasIps = await context.Aliases.Where(alias => alias.LinkId == linkId && alias.IPAddress != null) .Select(alias => alias.IPAddress) .ToListAsync(); + if (ip != null) { aliasIps.Add(ip); } - iqIpPenalties = context.Penalties - .Where(penalty => aliasIps.Contains(penalty.Offender.CurrentAlias.IPAddress)) - .Where(filter); + var clientIds = new List(); + + if (aliasIps.Any()) + { + clientIds = await context.Clients.Where(client => aliasIps.Contains(client.CurrentAlias.IPAddress)) + .Select(client => client.ClientId).ToListAsync(); + + } + + if (clientIds.Any()) + { + iqIpPenalties = context.Penalties.Where(penalty => clientIds.Contains(penalty.OffenderId)) + .Where(filter); + } + + else + { + iqIpPenalties = Enumerable.Empty().AsQueryable(); + } } - var activePenalties = (await iqLinkPenalties.ToListAsync()) - .Union(await iqIpPenalties.ToListAsync()) - .Distinct(); + var activeLinkPenalties = await iqLinkPenalties.ToListAsync(); + var activeIpPenalties = await iqIpPenalties.ToListAsync(); + var activePenalties = activeLinkPenalties.Concat(activeIpPenalties).Distinct(); // this is a bit more performant in memory (ordering) return activePenalties.OrderByDescending(p => p.When).ToList(); @@ -221,4 +238,4 @@ namespace SharedLibraryCore.Services await context.SaveChangesAsync(); } } -} \ No newline at end of file +}