more profile loading optimizations
This commit is contained in:
@ -168,10 +168,9 @@ namespace SharedLibraryCore.Services
|
||||
|
||||
public async Task<EFClient> Get(int entityId)
|
||||
{
|
||||
// todo: this needs to be optimized for large linked accounts
|
||||
await using var context = _contextFactory.CreateContext(false);
|
||||
|
||||
var client = context.Clients
|
||||
var client = await context.Clients
|
||||
.Select(_client => new EFClient
|
||||
{
|
||||
ClientId = _client.ClientId,
|
||||
@ -187,26 +186,28 @@ namespace SharedLibraryCore.Services
|
||||
Name = _client.CurrentAlias.Name,
|
||||
IPAddress = _client.CurrentAlias.IPAddress
|
||||
},
|
||||
TotalConnectionTime = _client.TotalConnectionTime
|
||||
TotalConnectionTime = _client.TotalConnectionTime,
|
||||
AliasLink = new EFAliasLink
|
||||
{
|
||||
AliasLinkId = _client.AliasLinkId,
|
||||
Children = _client.AliasLink.Children
|
||||
},
|
||||
LinkedAccounts = new Dictionary<int, long>()
|
||||
{
|
||||
{_client.ClientId, _client.NetworkId}
|
||||
}
|
||||
})
|
||||
.FirstOrDefault(_client => _client.ClientId == entityId);
|
||||
.FirstOrDefaultAsync(_client => _client.ClientId == entityId);
|
||||
|
||||
if (client == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
client.AliasLink = new EFAliasLink
|
||||
if (!_appConfig.EnableImplicitAccountLinking)
|
||||
{
|
||||
AliasLinkId = client.AliasLinkId,
|
||||
Children = await context.Aliases
|
||||
.Where(_alias => _alias.LinkId == client.AliasLinkId)
|
||||
.Select(_alias => new EFAlias
|
||||
{
|
||||
Name = _alias.Name,
|
||||
IPAddress = _alias.IPAddress
|
||||
}).ToListAsync()
|
||||
};
|
||||
return client;
|
||||
}
|
||||
|
||||
var foundClient = new
|
||||
{
|
||||
@ -220,11 +221,6 @@ namespace SharedLibraryCore.Services
|
||||
.ToListAsync()
|
||||
};
|
||||
|
||||
if (foundClient == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
foundClient.Client.LinkedAccounts = new Dictionary<int, long>();
|
||||
// todo: find out the best way to do this
|
||||
// I'm doing this here because I don't know the best way to have multiple awaits in the query
|
||||
|
@ -163,9 +163,6 @@ namespace SharedLibraryCore.Services
|
||||
(p.Expires == null || p.Expires > now);
|
||||
|
||||
await using var context = _contextFactory.CreateContext(false);
|
||||
var iqLinkPenalties = context.Penalties
|
||||
.Where(p => p.LinkId == linkId)
|
||||
.Where(filter);
|
||||
|
||||
IQueryable<EFPenalty> iqIpPenalties;
|
||||
|
||||
@ -178,35 +175,6 @@ namespace SharedLibraryCore.Services
|
||||
}
|
||||
else
|
||||
{
|
||||
/* var aliasIps = await context.Aliases.Where(alias => (alias.LinkId == linkId || alias.AliasId == currentAliasId) && alias.IPAddress != null)
|
||||
.Select(alias => alias.IPAddress)
|
||||
.ToListAsync();
|
||||
|
||||
if (ip != null)
|
||||
{
|
||||
aliasIps.Add(ip);
|
||||
}
|
||||
|
||||
var clientIds = new List<int>();
|
||||
|
||||
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<EFPenalty>().AsQueryable();
|
||||
}*/
|
||||
|
||||
var usedIps = await context.Aliases.AsNoTracking()
|
||||
.Where(alias => (alias.LinkId == linkId || alias.AliasId == currentAliasId) && alias.IPAddress != null)
|
||||
.Select(alias => alias.IPAddress).ToListAsync();
|
||||
@ -216,13 +184,12 @@ namespace SharedLibraryCore.Services
|
||||
.ToListAsync();
|
||||
|
||||
iqIpPenalties = context.Penalties.AsNoTracking()
|
||||
.Where(penalty => aliasedIds.Contains(penalty.LinkId))
|
||||
.Where(penalty => aliasedIds.Contains(penalty.LinkId) || penalty.LinkId == linkId)
|
||||
.Where(filter);
|
||||
}
|
||||
|
||||
var activeLinkPenalties = await iqLinkPenalties.ToListAsync();
|
||||
var activeIpPenalties = await iqIpPenalties.ToListAsync();
|
||||
var activePenalties = activeLinkPenalties.Concat(activeIpPenalties).Distinct();
|
||||
var activePenalties = activeIpPenalties.Distinct();
|
||||
|
||||
// this is a bit more performant in memory (ordering)
|
||||
return activePenalties.OrderByDescending(p => p.When).ToList();
|
||||
|
Reference in New Issue
Block a user