add index to time sent in EFCLientMessage, so we can retrieve faster in context view

set the maximum height of the
add link to profile on client chat
move change history into a seperate service
move around AC penalty processing
This commit is contained in:
RaidMax
2018-09-16 15:34:16 -05:00
parent 7c708f06f3
commit 4a46abc46d
30 changed files with 2662 additions and 1174 deletions

View File

@ -54,9 +54,10 @@ namespace SharedLibraryCore.Services
public async Task<IList<EFAlias>> Find(Func<EFAlias, bool> expression)
{
// todo: max better?
return await Task.Run(() =>
{
using (var context = new DatabaseContext())
using (var context = new DatabaseContext(true))
return context.Aliases
.AsNoTracking()
.Include(a => a.Link.Children)
@ -67,10 +68,9 @@ namespace SharedLibraryCore.Services
public async Task<EFAlias> Get(int entityID)
{
using (var context = new DatabaseContext())
using (var context = new DatabaseContext(true))
return await context.Aliases
.AsNoTracking()
.SingleOrDefaultAsync(e => e.AliasId == entityID);
.FirstOrDefaultAsync(e => e.AliasId == entityID);
}
public Task<EFAlias> GetUnique(long entityProperty)
@ -81,23 +81,6 @@ namespace SharedLibraryCore.Services
public async Task<EFAlias> Update(EFAlias entity)
{
throw await Task.FromResult(new Exception());
/*using (var context = new DatabaseContext())
{
entity = context.Aliases.Attach(entity);
context.Entry(entity).State = EntityState.Modified;
await context.SaveChangesAsync();
return entity;
}*/
}
public async Task<EFAliasLink> CreateLink(EFAliasLink link)
{
using (var context = new DatabaseContext())
{
context.AliasLinks.Add(link);
await context.SaveChangesAsync();
return link;
}
}
}
}

View File

@ -0,0 +1,95 @@
using SharedLibraryCore.Database;
using SharedLibraryCore.Database.Models;
using SharedLibraryCore.Events;
using SharedLibraryCore.Interfaces;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
namespace SharedLibraryCore.Services
{
public class ChangeHistoryService : IEntityService<EFChangeHistory>
{
public Task<EFChangeHistory> Create(EFChangeHistory entity)
{
throw new NotImplementedException();
}
public async Task<EFChangeHistory> Add(GameEvent e)
{
EFChangeHistory change = null;
switch (e.Type)
{
case GameEvent.EventType.Ban:
change = new EFChangeHistory()
{
OriginEntityId = e.Origin.ClientId,
TargetEntityId = e.Target.ClientId,
TypeOfChange = EFChangeHistory.ChangeType.Ban,
Comment = e.Data
};
break;
case GameEvent.EventType.Command:
break;
case GameEvent.EventType.ChangePermission:
change = new EFChangeHistory()
{
OriginEntityId = e.Origin.ClientId,
TargetEntityId = e.Target.ClientId,
TypeOfChange = EFChangeHistory.ChangeType.Permission,
PreviousValue = ((Change)e.Extra).PreviousValue,
CurrentValue = ((Change)e.Extra).NewValue
};
break;
default:
break;
}
if (change != null)
{
using (var ctx = new DatabaseContext(true))
{
ctx.EFChangeHistory.Add(change);
try
{
await ctx.SaveChangesAsync();
}
catch (Exception ex)
{
e.Owner.Logger.WriteDebug(ex.GetExceptionInfo());
}
}
}
return change;
}
public Task<EFChangeHistory> Delete(EFChangeHistory entity)
{
throw new NotImplementedException();
}
public Task<IList<EFChangeHistory>> Find(Func<EFChangeHistory, bool> expression)
{
throw new NotImplementedException();
}
public Task<EFChangeHistory> Get(int entityID)
{
throw new NotImplementedException();
}
public Task<EFChangeHistory> GetUnique(long entityProperty)
{
throw new NotImplementedException();
}
public Task<EFChangeHistory> Update(EFChangeHistory entity)
{
throw new NotImplementedException();
}
}
}

View File

@ -223,7 +223,7 @@ namespace SharedLibraryCore.Services
}
}
#region ServiceSpecific
#region ServiceSpecific
public async Task<IList<EFClient>> GetOwners()
{
using (var context = new DatabaseContext())
@ -262,7 +262,7 @@ namespace SharedLibraryCore.Services
name = name.ToLower();
using (var context = new DatabaseContext(true))
using (var context = new DatabaseContext(disableTracking: true))
{
int asIP = name.ConvertToIP();
// hack: so IW4MAdmin and bots don't show up in search results
@ -287,57 +287,9 @@ namespace SharedLibraryCore.Services
}
}
public async Task<IList<EFClient>> GetClientByIP(int ipAddress)
{
using (var context = new DatabaseContext(true))
{
var iqClients = (from alias in context.Aliases
.AsNoTracking()
where alias.IPAddress == ipAddress
join link in context.AliasLinks
on alias.LinkId equals link.AliasLinkId
join client in context.Clients
.AsNoTracking()
on alias.LinkId equals client.AliasLinkId
select client)
.Distinct()
.Include(c => c.CurrentAlias)
.Include(c => c.AliasLink.Children);
return await iqClients.ToListAsync();
}
}
public async Task<IList<EFClient>> GetRecentClients(int offset, int count)
{
using (var context = new DatabaseContext())
return await context.Clients
.AsNoTracking()
.Include(c => c.CurrentAlias)
.Include(p => p.AliasLink)
.OrderByDescending(p => p.ClientId)
.Skip(offset)
.Take(count)
.ToListAsync();
}
public async Task<IList<EFClient>> PruneInactivePrivilegedClients(int inactiveDays)
{
using (var context = new DatabaseContext())
{
var inactive = await context.Clients.Where(c => c.Level > Objects.Player.Permission.Flagged)
.AsNoTracking()
.Where(c => (DateTime.UtcNow - c.LastConnection).TotalDays >= inactiveDays)
.ToListAsync();
inactive.ForEach(c => c.Level = Player.Permission.User);
await context.SaveChangesAsync();
return inactive;
}
}
public async Task<int> GetTotalClientsAsync()
{
using (var context = new DatabaseContext())
using (var context = new DatabaseContext(true))
return await context.Clients
.CountAsync();
}
@ -349,9 +301,9 @@ namespace SharedLibraryCore.Services
public async Task<int> GetTotalPlayTime()
{
using (var context = new DatabaseContext())
using (var context = new DatabaseContext(true))
return await context.Clients.SumAsync(c => c.TotalConnectionTime);
}
#endregion
#endregion
}
}