update getpairedclients to use only one query instead of one per entry
This commit is contained in:
@@ -93,21 +93,36 @@ namespace MareSynchronosServer.Hubs
|
|||||||
public async Task<List<ClientPairDto>> GetPairedClients()
|
public async Task<List<ClientPairDto>> GetPairedClients()
|
||||||
{
|
{
|
||||||
string userid = AuthenticatedUserId;
|
string userid = AuthenticatedUserId;
|
||||||
var pairs = await _dbContext.ClientPairs.AsNoTracking()
|
var query =
|
||||||
.Include(u => u.OtherUser)
|
from userToOther in _dbContext.ClientPairs
|
||||||
.Include(u => u.User)
|
join otherToUser in _dbContext.ClientPairs
|
||||||
.Where(w => w.User.UID == userid)
|
on new
|
||||||
.ToListAsync();
|
{
|
||||||
return pairs.Select(w =>
|
user = userToOther.UserUID,
|
||||||
{
|
other = userToOther.OtherUserUID
|
||||||
var otherEntry = OppositeEntry(w.OtherUser.UID);
|
|
||||||
return new ClientPairDto
|
} equals new
|
||||||
|
{
|
||||||
|
user = otherToUser.OtherUserUID,
|
||||||
|
other = otherToUser.UserUID
|
||||||
|
} into leftJoin
|
||||||
|
from otherEntry in leftJoin.DefaultIfEmpty()
|
||||||
|
where
|
||||||
|
userToOther.UserUID == userid
|
||||||
|
select new
|
||||||
{
|
{
|
||||||
IsPaused = w.IsPaused,
|
userToOther.IsPaused,
|
||||||
OtherUID = w.OtherUser.UID,
|
OtherIsPaused = otherEntry != null && otherEntry.IsPaused,
|
||||||
IsSynced = otherEntry != null,
|
userToOther.OtherUserUID,
|
||||||
IsPausedFromOthers = otherEntry?.IsPaused ?? false,
|
IsSynced = otherEntry != null
|
||||||
};
|
};
|
||||||
|
|
||||||
|
return (await query.ToListAsync()).Select(f => new ClientPairDto()
|
||||||
|
{
|
||||||
|
IsPaused = f.IsPaused,
|
||||||
|
OtherUID = f.OtherUserUID,
|
||||||
|
IsSynced = f.IsSynced,
|
||||||
|
IsPausedFromOthers = f.OtherIsPaused
|
||||||
}).ToList();
|
}).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user