mirror of
https://github.com/Caraxi/mare.server.git
synced 2025-12-15 13:34:15 +01:00
update getpairedclients to use only one query instead of one per entry
This commit is contained in:
parent
7abe4f9f2e
commit
78543d0fc2
1 changed files with 28 additions and 13 deletions
|
|
@ -93,21 +93,36 @@ namespace MareSynchronosServer.Hubs
|
|||
public async Task<List<ClientPairDto>> GetPairedClients()
|
||||
{
|
||||
string userid = AuthenticatedUserId;
|
||||
var pairs = await _dbContext.ClientPairs.AsNoTracking()
|
||||
.Include(u => u.OtherUser)
|
||||
.Include(u => u.User)
|
||||
.Where(w => w.User.UID == userid)
|
||||
.ToListAsync();
|
||||
return pairs.Select(w =>
|
||||
var query =
|
||||
from userToOther in _dbContext.ClientPairs
|
||||
join otherToUser in _dbContext.ClientPairs
|
||||
on new
|
||||
{
|
||||
var otherEntry = OppositeEntry(w.OtherUser.UID);
|
||||
return new ClientPairDto
|
||||
user = userToOther.UserUID,
|
||||
other = userToOther.OtherUserUID
|
||||
|
||||
} equals new
|
||||
{
|
||||
IsPaused = w.IsPaused,
|
||||
OtherUID = w.OtherUser.UID,
|
||||
IsSynced = otherEntry != null,
|
||||
IsPausedFromOthers = otherEntry?.IsPaused ?? false,
|
||||
user = otherToUser.OtherUserUID,
|
||||
other = otherToUser.UserUID
|
||||
} into leftJoin
|
||||
from otherEntry in leftJoin.DefaultIfEmpty()
|
||||
where
|
||||
userToOther.UserUID == userid
|
||||
select new
|
||||
{
|
||||
userToOther.IsPaused,
|
||||
OtherIsPaused = otherEntry != null && otherEntry.IsPaused,
|
||||
userToOther.OtherUserUID,
|
||||
IsSynced = otherEntry != null
|
||||
};
|
||||
|
||||
return (await query.ToListAsync()).Select(f => new ClientPairDto()
|
||||
{
|
||||
IsPaused = f.IsPaused,
|
||||
OtherUID = f.OtherUserUID,
|
||||
IsSynced = f.IsSynced,
|
||||
IsPausedFromOthers = f.OtherIsPaused
|
||||
}).ToList();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue