mirror of
https://github.com/Caraxi/mare.server.git
synced 2025-12-12 22:17:22 +01:00
optimize further
This commit is contained in:
parent
89951ca084
commit
2fe312ad67
1 changed files with 6 additions and 19 deletions
|
|
@ -77,9 +77,7 @@ public partial class MareHub
|
||||||
{
|
{
|
||||||
uid ??= UserUID;
|
uid ??= UserUID;
|
||||||
|
|
||||||
return (await GetBasicPairInfo(UserUID).ConfigureAwait(false))
|
return (await GetSyncedUnpausedOnlinePairs(UserUID).ConfigureAwait(false));
|
||||||
.Where(u => u.Value.IsSynced && !u.Value.IsPaused)
|
|
||||||
.Select(u => u.Key).ToList();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<Dictionary<string, string>> GetOnlineUsers(List<string> uids)
|
private async Task<Dictionary<string, string>> GetOnlineUsers(List<string> uids)
|
||||||
|
|
@ -419,7 +417,7 @@ public partial class MareHub
|
||||||
}, StringComparer.Ordinal);
|
}, StringComparer.Ordinal);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<Dictionary<string, BasicUserInfo>> GetBasicPairInfo(string uid)
|
private async Task<List<string>> GetSyncedUnpausedOnlinePairs(string uid)
|
||||||
{
|
{
|
||||||
var clientPairs = from cp in _dbContext.ClientPairs.AsNoTracking().Where(u => u.UserUID == uid)
|
var clientPairs = from cp in _dbContext.ClientPairs.AsNoTracking().Where(u => u.UserUID == uid)
|
||||||
join cp2 in _dbContext.ClientPairs.AsNoTracking().Where(u => u.OtherUserUID == uid)
|
join cp2 in _dbContext.ClientPairs.AsNoTracking().Where(u => u.OtherUserUID == uid)
|
||||||
|
|
@ -434,12 +432,11 @@ public partial class MareHub
|
||||||
OtherUserUID = cp2.UserUID
|
OtherUserUID = cp2.UserUID
|
||||||
} into joined
|
} into joined
|
||||||
from c in joined.DefaultIfEmpty()
|
from c in joined.DefaultIfEmpty()
|
||||||
where cp.UserUID == uid
|
where cp.UserUID == uid && c.UserUID != null
|
||||||
select new
|
select new
|
||||||
{
|
{
|
||||||
UserUID = cp.UserUID,
|
UserUID = cp.UserUID,
|
||||||
OtherUserUID = cp.OtherUserUID,
|
OtherUserUID = cp.OtherUserUID,
|
||||||
Synced = c != null
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -457,7 +454,6 @@ public partial class MareHub
|
||||||
{
|
{
|
||||||
UserUID = gp.GroupUserUID,
|
UserUID = gp.GroupUserUID,
|
||||||
OtherUserUID = gp2.GroupUserUID,
|
OtherUserUID = gp2.GroupUserUID,
|
||||||
Synced = true
|
|
||||||
};
|
};
|
||||||
|
|
||||||
var allPairs = clientPairs.Concat(groupPairs);
|
var allPairs = clientPairs.Concat(groupPairs);
|
||||||
|
|
@ -476,20 +472,11 @@ public partial class MareHub
|
||||||
where user.UserUID == uid
|
where user.UserUID == uid
|
||||||
&& ownperm.UserUID == user.UserUID && ownperm.OtherUserUID == user.OtherUserUID
|
&& ownperm.UserUID == user.UserUID && ownperm.OtherUserUID == user.OtherUserUID
|
||||||
&& otherperm.OtherUserUID == user.UserUID && otherperm.UserUID == user.OtherUserUID
|
&& otherperm.OtherUserUID == user.UserUID && otherperm.UserUID == user.OtherUserUID
|
||||||
select new
|
&& !ownperm.IsPaused && (otherperm == null ? false : !otherperm.IsPaused)
|
||||||
{
|
select user.OtherUserUID;
|
||||||
OtherUserUID = user.OtherUserUID,
|
|
||||||
Synced = user.Synced,
|
|
||||||
IsPaused = ownperm.IsPaused || otherperm == null ? true : otherperm.IsPaused
|
|
||||||
};
|
|
||||||
|
|
||||||
var resultList = await result.AsNoTracking().ToListAsync().ConfigureAwait(false);
|
return await result.Distinct().AsNoTracking().ToListAsync().ConfigureAwait(false);
|
||||||
return resultList.GroupBy(g => g.OtherUserUID, StringComparer.Ordinal).ToDictionary(g => g.Key, g =>
|
|
||||||
{
|
|
||||||
return new BasicUserInfo(g.Max(p => p.Synced), g.First().IsPaused);
|
|
||||||
}, StringComparer.Ordinal);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public record UserInfo(string Alias, bool IndividuallyPaired, bool IsSynced, List<string> GIDs, UserPermissionSet? OwnPermissions, UserPermissionSet? OtherPermissions);
|
public record UserInfo(string Alias, bool IndividuallyPaired, bool IsSynced, List<string> GIDs, UserPermissionSet? OwnPermissions, UserPermissionSet? OtherPermissions);
|
||||||
public record BasicUserInfo(bool IsSynced, bool IsPaused);
|
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue