Skip to content

Commit

Permalink
Revert "[PM-1191] chore: simplify queries"
Browse files Browse the repository at this point in the history
This reverts commit f57443d.
  • Loading branch information
coroiu committed Mar 3, 2023
1 parent f57443d commit 5119608
Showing 1 changed file with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -188,25 +188,29 @@ where cg.CollectionId.Equals(id)
var groups =
from c in collections
join cg in dbContext.CollectionGroups on c.Id equals cg.CollectionId
select cg;
group cg by cg.CollectionId into g
select g;
var users =
from c in collections
join cu in dbContext.CollectionUsers on c.Id equals cu.CollectionId
select cu;
group cu by cu.CollectionId into u
select u;

return collections.Select(collection =>
new Tuple<Core.Entities.Collection, CollectionAccessDetails>(
collection,
new CollectionAccessDetails
{
Groups = groups
.FirstOrDefault(g => g.Key == collection.Id)?
.Select(g => new CollectionAccessSelection
{
Id = g.GroupId,
HidePasswords = g.HidePasswords,
ReadOnly = g.ReadOnly
}).ToList() ?? new List<CollectionAccessSelection>(),
Users = users
.FirstOrDefault(u => u.Key == collection.Id)?
.Select(c => new CollectionAccessSelection
{
Id = c.OrganizationUserId,
Expand All @@ -228,25 +232,29 @@ join cu in dbContext.CollectionUsers on c.Id equals cu.CollectionId
var groups =
from c in collections
join cg in dbContext.CollectionGroups on c.Id equals cg.CollectionId
select cg;
group cg by cg.CollectionId into g
select g;
var users =
from c in collections
join cu in dbContext.CollectionUsers on c.Id equals cu.CollectionId
select cu;
group cu by cu.CollectionId into u
select u;

return collections.Select(collection =>
new Tuple<Core.Entities.Collection, CollectionAccessDetails>(
collection,
new CollectionAccessDetails
{
Groups = groups
.FirstOrDefault(g => g.Key == collection.Id)?
.Select(g => new CollectionAccessSelection
{
Id = g.GroupId,
HidePasswords = g.HidePasswords,
ReadOnly = g.ReadOnly
}).ToList() ?? new List<CollectionAccessSelection>(),
Users = users
.FirstOrDefault(u => u.Key == collection.Id)?
.Select(c => new CollectionAccessSelection
{
Id = c.OrganizationUserId,
Expand Down

0 comments on commit 5119608

Please sign in to comment.