Skip to content

Commit 983f415

Browse files
committed
fix(front): fetch service accounts with describe_many endpoint
1 parent b8a0d0e commit 983f415

File tree

1 file changed

+11
-16
lines changed

1 file changed

+11
-16
lines changed

front/lib/front/rbac/groups.ex

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -130,24 +130,19 @@ defmodule Front.RBAC.Groups do
130130
member_user_ids = members |> Enum.map(& &1.id)
131131
non_member_ids = group.member_ids -- member_user_ids
132132

133-
# N+1 :see_no_evil
134133
service_accounts =
135-
non_member_ids
136-
|> Enum.map(fn service_account_id ->
137-
Front.ServiceAccount.describe(service_account_id)
138-
end)
139-
|> Enum.map(fn
140-
{:ok, service_account} ->
141-
%{
142-
id: service_account.id,
143-
name: service_account.name,
144-
avatar: ""
145-
}
146-
134+
Front.ServiceAccount.describe_many(non_member_ids)
135+
|> case do
136+
{:ok, service_accounts} ->
137+
service_accounts
147138
_ ->
148-
nil
149-
end)
150-
|> Enum.filter(& &1)
139+
[]
140+
end
141+
|> Enum.map(&%{
142+
id: &1.id,
143+
name: &1.name,
144+
avatar: ""
145+
})
151146

152147
group |> Map.put(:members, members ++ service_accounts)
153148
end

0 commit comments

Comments
 (0)