removed defaults from FirstOrDefault to avoid reading everything with ToList
This commit is contained in:
parent
24ad2b11e5
commit
a4c29d8891
6 changed files with 50 additions and 36 deletions
|
@ -74,8 +74,9 @@ namespace Lieb.Data
|
||||||
.Include(r => r.SignUps)
|
.Include(r => r.SignUps)
|
||||||
.ThenInclude(s => s.RaidRole)
|
.ThenInclude(s => s.RaidRole)
|
||||||
.Include(r => r.DiscordRaidMessages)
|
.Include(r => r.DiscordRaidMessages)
|
||||||
.ToList()
|
.FirstOrDefault(r => r.RaidId == raidId);
|
||||||
.FirstOrDefault(r => r.RaidId == raidId, new Raid());
|
|
||||||
|
if(raid == null) return;
|
||||||
|
|
||||||
var httpClient = _httpClientFactory.CreateClient(Constants.HttpClientName);
|
var httpClient = _httpClientFactory.CreateClient(Constants.HttpClientName);
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,6 @@ namespace Lieb.Data
|
||||||
using var context = _contextFactory.CreateDbContext();
|
using var context = _contextFactory.CreateDbContext();
|
||||||
Raid? raid = context.Raids
|
Raid? raid = context.Raids
|
||||||
.Include(r => r.Roles)
|
.Include(r => r.Roles)
|
||||||
.Include(r => r.RaidLogs)
|
|
||||||
.Include(r => r.Reminders)
|
.Include(r => r.Reminders)
|
||||||
.Include(r => r.SignUps)
|
.Include(r => r.SignUps)
|
||||||
.ThenInclude(s => s.LiebUser)
|
.ThenInclude(s => s.LiebUser)
|
||||||
|
|
|
@ -34,9 +34,8 @@ namespace Lieb.Data
|
||||||
public Raid GetRaid(int raidId)
|
public Raid GetRaid(int raidId)
|
||||||
{
|
{
|
||||||
using var context = _contextFactory.CreateDbContext();
|
using var context = _contextFactory.CreateDbContext();
|
||||||
return context.Raids
|
Raid raid = context.Raids
|
||||||
.Include(r => r.Roles)
|
.Include(r => r.Roles)
|
||||||
.Include(r => r.RaidLogs)
|
|
||||||
.Include(r => r.Reminders)
|
.Include(r => r.Reminders)
|
||||||
.Include(r => r.SignUps)
|
.Include(r => r.SignUps)
|
||||||
.ThenInclude(s => s.LiebUser)
|
.ThenInclude(s => s.LiebUser)
|
||||||
|
@ -45,8 +44,9 @@ namespace Lieb.Data
|
||||||
.Include(r => r.SignUps)
|
.Include(r => r.SignUps)
|
||||||
.ThenInclude(s => s.RaidRole)
|
.ThenInclude(s => s.RaidRole)
|
||||||
.Include(r => r.DiscordRaidMessages)
|
.Include(r => r.DiscordRaidMessages)
|
||||||
.ToList()
|
.FirstOrDefault(r => r.RaidId == raidId);
|
||||||
.FirstOrDefault(r => r.RaidId == raidId, new Raid());
|
if(raid != null) return raid;
|
||||||
|
else return new Raid();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task AddOrEditRaid(Raid raid, List<RaidRole> rolesToDelete, List<RaidReminder> remindersToDelete, List<DiscordRaidMessage> messagesToDelete, ulong? changedBy)
|
public async Task AddOrEditRaid(Raid raid, List<RaidRole> rolesToDelete, List<RaidReminder> remindersToDelete, List<DiscordRaidMessage> messagesToDelete, ulong? changedBy)
|
||||||
|
@ -111,16 +111,19 @@ namespace Lieb.Data
|
||||||
|
|
||||||
if(userId != null)
|
if(userId != null)
|
||||||
{
|
{
|
||||||
LiebUser user = context.LiebUsers.ToList().FirstOrDefault(u => u.Id == userId, new LiebUser());
|
LiebUser user = context.LiebUsers.FirstOrDefault(u => u.Id == userId);
|
||||||
RaidLog logEntry = new RaidLog()
|
if(user != null)
|
||||||
{
|
{
|
||||||
LogEntry = $"The Raid \"{raid.Title}\" was deleted by {user.Name}",
|
RaidLog logEntry = new RaidLog()
|
||||||
Time = DateTimeOffset.UtcNow,
|
{
|
||||||
Type = RaidLog.LogType.Raid,
|
LogEntry = $"The Raid \"{raid.Title}\" was deleted by {user.Name}",
|
||||||
UserId = userId
|
Time = DateTimeOffset.UtcNow,
|
||||||
};
|
Type = RaidLog.LogType.Raid,
|
||||||
context.RaidLogs.Add(logEntry);
|
UserId = userId
|
||||||
await context.SaveChangesAsync();
|
};
|
||||||
|
context.RaidLogs.Add(logEntry);
|
||||||
|
await context.SaveChangesAsync();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -487,8 +490,9 @@ namespace Lieb.Data
|
||||||
|
|
||||||
Raid raid = context.Raids
|
Raid raid = context.Raids
|
||||||
.Include(r => r.DiscordRaidMessages)
|
.Include(r => r.DiscordRaidMessages)
|
||||||
.ToList()
|
.FirstOrDefault(r => r.RaidId == signUp.RaidId);
|
||||||
.FirstOrDefault(r => r.RaidId == signUp.RaidId, new Raid());
|
|
||||||
|
if(raid == null) return;
|
||||||
|
|
||||||
if(raid.DiscordRaidMessages.Count > 0)
|
if(raid.DiscordRaidMessages.Count > 0)
|
||||||
{
|
{
|
||||||
|
@ -496,9 +500,12 @@ namespace Lieb.Data
|
||||||
if(signedUpBy > 0)
|
if(signedUpBy > 0)
|
||||||
{
|
{
|
||||||
LiebUser signedUpByUser = context.LiebUsers
|
LiebUser signedUpByUser = context.LiebUsers
|
||||||
.ToList()
|
.FirstOrDefault(u => u.Id == signedUpBy);
|
||||||
.FirstOrDefault(u => u.Id == signedUpBy, new LiebUser());
|
|
||||||
signedUpByUserName = signedUpByUser.Name;
|
if(signedUpByUser != null)
|
||||||
|
signedUpByUserName = signedUpByUser.Name;
|
||||||
|
else
|
||||||
|
signedUpByUserName = "user not found";
|
||||||
}
|
}
|
||||||
|
|
||||||
string message = $"{signedUpByUserName} signed up {userName} as {signUp.SignUpType.ToString()}";
|
string message = $"{signedUpByUserName} signed up {userName} as {signUp.SignUpType.ToString()}";
|
||||||
|
|
|
@ -32,7 +32,6 @@ namespace Lieb.Data
|
||||||
.Include(r => r.Roles)
|
.Include(r => r.Roles)
|
||||||
.Include(r => r.Reminders)
|
.Include(r => r.Reminders)
|
||||||
.Include(r => r.DiscordRaidMessages)
|
.Include(r => r.DiscordRaidMessages)
|
||||||
.Include(r => r.TemplateLogs)
|
|
||||||
.FirstOrDefault(t => t.RaidTemplateId == raidTemplateId);
|
.FirstOrDefault(t => t.RaidTemplateId == raidTemplateId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,16 +74,19 @@ namespace Lieb.Data
|
||||||
context.RaidTemplates.Remove(template);
|
context.RaidTemplates.Remove(template);
|
||||||
await context.SaveChangesAsync();
|
await context.SaveChangesAsync();
|
||||||
|
|
||||||
LiebUser user = context.LiebUsers.ToList().FirstOrDefault(u => u.Id == userId, new LiebUser());
|
LiebUser user = context.LiebUsers.FirstOrDefault(u => u.Id == userId);
|
||||||
RaidLog logEntry = new RaidLog()
|
if(user != null)
|
||||||
{
|
{
|
||||||
LogEntry = $"The Template \"{template.Title}\" was deleted by {user.Name}",
|
RaidLog logEntry = new RaidLog()
|
||||||
Time = DateTimeOffset.UtcNow,
|
{
|
||||||
Type = RaidLog.LogType.RaidTemplate,
|
LogEntry = $"The Template \"{template.Title}\" was deleted by {user.Name}",
|
||||||
UserId = userId
|
Time = DateTimeOffset.UtcNow,
|
||||||
};
|
Type = RaidLog.LogType.RaidTemplate,
|
||||||
context.RaidLogs.Add(logEntry);
|
UserId = userId
|
||||||
await context.SaveChangesAsync();
|
};
|
||||||
|
context.RaidLogs.Add(logEntry);
|
||||||
|
await context.SaveChangesAsync();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task CreateRaidFromTemplate(int raidTempalteId)
|
public async Task CreateRaidFromTemplate(int raidTempalteId)
|
||||||
|
|
|
@ -66,8 +66,10 @@ namespace Lieb.Data
|
||||||
using var context = _contextFactory.CreateDbContext();
|
using var context = _contextFactory.CreateDbContext();
|
||||||
LiebUser user = context.LiebUsers
|
LiebUser user = context.LiebUsers
|
||||||
.Include(u => u.GuildWars2Accounts)
|
.Include(u => u.GuildWars2Accounts)
|
||||||
.ToList()
|
|
||||||
.FirstOrDefault(u => u.Id == userId, new LiebUser());
|
.FirstOrDefault(u => u.Id == userId, new LiebUser());
|
||||||
|
|
||||||
|
if(user == null) return new GuildWars2Account();
|
||||||
|
|
||||||
return user.GuildWars2Accounts.FirstOrDefault(g => g.GuildWars2AccountId == user.MainGW2Account, new GuildWars2Account());
|
return user.GuildWars2Accounts.FirstOrDefault(g => g.GuildWars2AccountId == user.MainGW2Account, new GuildWars2Account());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -284,8 +286,9 @@ namespace Lieb.Data
|
||||||
using var context = _contextFactory.CreateDbContext();
|
using var context = _contextFactory.CreateDbContext();
|
||||||
LiebUser user = GetLiebUserGW2AccountOnly(userId);
|
LiebUser user = GetLiebUserGW2AccountOnly(userId);
|
||||||
Raid raid = context.Raids
|
Raid raid = context.Raids
|
||||||
.ToList()
|
.FirstOrDefault(r => r.RaidId == raidId);
|
||||||
.FirstOrDefault(r => r.RaidId == raidId, new Raid());
|
|
||||||
|
if(raid == null) return new List<GuildWars2Account>();
|
||||||
|
|
||||||
List<GuildWars2Account> accounts = GetAllUsableAccounts(user, raid.RaidType);
|
List<GuildWars2Account> accounts = GetAllUsableAccounts(user, raid.RaidType);
|
||||||
if(user.AlwaysSignUpWithMainAccount && accounts.Where(a => a.GuildWars2AccountId == user.MainGW2Account).Any())
|
if(user.AlwaysSignUpWithMainAccount && accounts.Where(a => a.GuildWars2AccountId == user.MainGW2Account).Any())
|
||||||
|
@ -303,8 +306,9 @@ namespace Lieb.Data
|
||||||
using var context = _contextFactory.CreateDbContext();
|
using var context = _contextFactory.CreateDbContext();
|
||||||
LiebUser user = GetLiebUserGW2AccountOnly(userId);
|
LiebUser user = GetLiebUserGW2AccountOnly(userId);
|
||||||
Raid raid = context.Raids
|
Raid raid = context.Raids
|
||||||
.ToList()
|
.FirstOrDefault(r => r.RaidId == raidId);
|
||||||
.FirstOrDefault(r => r.RaidId == raidId, new Raid());
|
|
||||||
|
if(raid == null) return 0;
|
||||||
|
|
||||||
List<GuildWars2Account> usableAccounts = GetAllUsableAccounts(user, raid.RaidType);
|
List<GuildWars2Account> usableAccounts = GetAllUsableAccounts(user, raid.RaidType);
|
||||||
|
|
||||||
|
|
|
@ -72,6 +72,7 @@ namespace Lieb.Models.GuildWars2.Raid
|
||||||
this.RequiredRole = template.RequiredRole;
|
this.RequiredRole = template.RequiredRole;
|
||||||
this.MoveFlexUsers = template.MoveFlexUsers;
|
this.MoveFlexUsers = template.MoveFlexUsers;
|
||||||
this.RaidOwnerId = template.RaidOwnerId;
|
this.RaidOwnerId = template.RaidOwnerId;
|
||||||
|
this.EventType = template.EventType;
|
||||||
|
|
||||||
foreach (RaidRole role in template.Roles)
|
foreach (RaidRole role in template.Roles)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue