Skip to content

Commit 5430df2

Browse files
committed
fix and simplify bounty queries
1 parent 1e2e03a commit 5430df2

File tree

2 files changed

+12
-55
lines changed

2 files changed

+12
-55
lines changed

lib/algora/bounties/bounties.ex

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -771,8 +771,18 @@ defmodule Algora.Bounties do
771771
end
772772

773773
def fetch_stats(org_id \\ nil) do
774-
open_bounties_query = Bounty.filter_by_org_id(Bounty.open(), org_id)
775-
rewarded_bounties_query = Bounty.filter_by_org_id(Bounty.completed(), org_id)
774+
open_bounties_query =
775+
from b in Bounty,
776+
join: u in assoc(b, :owner),
777+
where: u.id == ^org_id,
778+
where: b.status == :open
779+
780+
rewarded_bounties_query =
781+
from b in Bounty,
782+
join: u in assoc(b, :owner),
783+
where: u.id == ^org_id,
784+
where: b.status == :paid
785+
776786
rewarded_claims_query = Claim.filter_by_org_id(Claim.rewarded(), org_id)
777787
members_query = Member.filter_by_org_id(Member, org_id)
778788

lib/algora/bounties/schemas/bounty.ex

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -68,51 +68,6 @@ defmodule Algora.Bounties.Bounty do
6868
|> String.replace(~r/\/(issues|pull|discussions)\//, "#")
6969
end
7070

71-
def open(query \\ Bounty) do
72-
from b in query,
73-
as: :bounties,
74-
where:
75-
not exists(
76-
from(
77-
t in Transaction,
78-
where:
79-
parent_as(:bounties).id == t.bounty_id and
80-
not is_nil(t.succeeded_at) and
81-
t.type == :transfer
82-
)
83-
)
84-
end
85-
86-
def completed(query \\ Bounty) do
87-
from b in query,
88-
as: :bounties,
89-
where:
90-
exists(
91-
from(
92-
t in Transaction,
93-
where:
94-
parent_as(:bounties).id == t.bounty_id and
95-
not is_nil(t.succeeded_at) and
96-
t.type == :transfer
97-
)
98-
)
99-
end
100-
101-
def rewarded(query \\ Bounty) do
102-
from b in query,
103-
as: :bounties,
104-
where:
105-
exists(
106-
from(
107-
t in Transaction,
108-
where:
109-
parent_as(:bounties).id == t.bounty_id and
110-
not is_nil(t.succeeded_at) and
111-
t.type == :transfer
112-
)
113-
)
114-
end
115-
11671
def order_by_most_recent(query \\ Bounty) do
11772
from(b in query, order_by: [desc: b.inserted_at])
11873
end
@@ -121,14 +76,6 @@ defmodule Algora.Bounties.Bounty do
12176
from(b in query, limit: ^limit)
12277
end
12378

124-
def filter_by_org_id(query, nil), do: query
125-
126-
def filter_by_org_id(query, org_id) do
127-
from b in query,
128-
join: u in assoc(b, :owner),
129-
where: u.id == ^org_id
130-
end
131-
13279
def filter_by_tech_stack(query, []), do: query
13380
def filter_by_tech_stack(query, nil), do: query
13481

0 commit comments

Comments
 (0)