Skip to content

Commit 76bf595

Browse files
committed
refactor: fix payable claims query in organization dashboard
- Introduced a new query to fetch paid bounties, improving the logic for determining payable claims. - Updated the join conditions and distinct selection to enhance performance and clarity in the assignment of payable bounties.
1 parent 58c105d commit 76bf595

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

lib/algora_web/live/org/dashboard_live.ex

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -950,20 +950,28 @@ defmodule AlgoraWeb.Org.DashboardLive do
950950
defp assign_payable_bounties(socket) do
951951
org = socket.assigns.current_org
952952

953+
paid_bounties_query =
954+
from b in Bounty,
955+
join: t in Transaction,
956+
on: t.bounty_id == b.id,
957+
where: t.type == :debit,
958+
where: t.status == :succeeded,
959+
where: t.user_id == ^org.id,
960+
select: b.id
961+
953962
payable_claims =
954963
Repo.all(
955964
from c in Claim,
956965
where: c.status == :approved,
966+
join: b in Bounty,
967+
on: b.ticket_id == c.target_id and b.owner_id == ^org.id,
968+
where: b.id not in subquery(paid_bounties_query),
957969
join: t in assoc(c, :target),
958-
join: b in assoc(t, :bounties),
959-
where: b.owner_id == ^org.id,
960-
left_join: tx in Transaction,
961-
on: tx.claim_id == c.id and tx.type == :debit,
962-
where: is_nil(tx.status) or tx.status not in [:initialized, :succeeded],
963970
join: r in assoc(t, :repository),
964971
join: ru in assoc(r, :user),
965972
join: cu in assoc(c, :user),
966973
left_join: s in assoc(c, :source),
974+
distinct: b.id,
967975
select_merge: %{
968976
user: cu,
969977
source: s,

0 commit comments

Comments
 (0)