Skip to content

Commit 4ef2bdb

Browse files
committed
refactor: enhance job matching and contribution queries
- Updated `get_job_matches` and `get_job_matches_count` to accept options for better flexibility. - Modified `list_user_contributions` to handle tech stack filtering more effectively, including a strict mode for "Haskell". - Improved query logic to utilize the updated options in both job and contribution contexts.
1 parent 7d6810c commit 4ef2bdb

File tree

3 files changed

+29
-14
lines changed

3 files changed

+29
-14
lines changed

lib/algora/settings/settings.ex

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,45 +103,47 @@ defmodule Algora.Settings do
103103
end
104104

105105
def get_job_matches(job, opts \\ []) do
106-
limit = Keyword.get(opts, :limit, 1000)
106+
opts = Keyword.put_new(opts, :limit, 1000)
107107

108108
case get("job_matches:#{job.id}") do
109109
%{"matches" => matches} when is_list(matches) ->
110110
matches
111111
|> load_matches()
112-
|> Enum.take(limit)
112+
|> Enum.take(opts[:limit])
113113

114114
_ ->
115115
[
116116
tech_stack: job.tech_stack,
117-
limit: limit,
118-
email_required: true,
117+
email_required: false,
119118
sort_by:
120119
case get_job_criteria(job) do
121120
criteria when map_size(criteria) > 0 -> criteria
122121
_ -> [{"solver", true}]
123122
end
124123
]
124+
|> Keyword.merge(opts)
125125
|> Algora.Cloud.list_top_matches()
126126
|> load_matches_2()
127127
end
128128
end
129129

130-
def get_job_matches_count(job) do
130+
def get_job_matches_count(job, opts \\ []) do
131131
case get("job_matches:#{job.id}") do
132132
%{"matches" => matches} when is_list(matches) ->
133133
length(matches)
134134

135135
_ ->
136-
Algora.Cloud.count_top_matches(
136+
[
137137
tech_stack: job.tech_stack,
138-
email_required: true,
138+
email_required: false,
139139
sort_by:
140140
case get_job_criteria(job) do
141141
criteria when map_size(criteria) > 0 -> criteria
142142
_ -> [{"solver", true}]
143143
end
144-
)
144+
]
145+
|> Keyword.merge(opts)
146+
|> Algora.Cloud.count_top_matches()
145147
end
146148
end
147149

lib/algora/workspace/workspace.ex

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,12 @@ defmodule Algora.Workspace do
641641

642642
@spec list_user_contributions(list(String.t()), Keyword.t()) :: {:ok, list(map())} | {:error, term()}
643643
def list_user_contributions(ids, opts \\ []) do
644+
tech_stack = opts[:tech_stack] || []
645+
646+
tech_stack = if "Haskell" in tech_stack, do: ["Haskell"], else: tech_stack
647+
648+
strict_tech_stack = "Haskell" in tech_stack || opts[:strict_tech_stack]
649+
644650
query =
645651
from uc in UserContribution,
646652
where: uc.user_id in ^ids,
@@ -660,7 +666,7 @@ defmodule Algora.Workspace do
660666
ilike(repo_owner.provider_login, "%firstcontributions%") or
661667
repo_owner.provider_login == "up-for-grabs"),
662668
order_by: [
663-
desc: fragment("CASE WHEN ? && ?::citext[] THEN 1 ELSE 0 END", r.tech_stack, ^(opts[:tech_stack] || [])),
669+
desc: fragment("CASE WHEN ? && ?::citext[] THEN 1 ELSE 0 END", r.tech_stack, ^tech_stack),
664670
desc: r.stargazers_count
665671
],
666672
select: %UserContribution{
@@ -683,8 +689,8 @@ defmodule Algora.Workspace do
683689
end
684690

685691
query =
686-
if opts[:strict_tech_stack] do
687-
where(query, [uc, u, r, repo_owner], fragment("? && ?::citext[]", r.tech_stack, ^(opts[:tech_stack] || [])))
692+
if strict_tech_stack do
693+
where(query, [uc, u, r, repo_owner], fragment("? && ?::citext[]", r.tech_stack, ^tech_stack))
688694
else
689695
query
690696
end

lib/algora_web/live/org/job_live.ex

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ defmodule AlgoraWeb.Org.JobLive do
199199
</div>
200200
</div>
201201
</div>
202-
<div class="hidden md:flex flex-col items-center">
202+
<div class="hidden md:flex flex-col items-center shrink-0">
203203
<h3 class="text-lg font-semibold">
204204
Share on socials
205205
</h3>
@@ -549,14 +549,21 @@ defmodule AlgoraWeb.Org.JobLive do
549549
{:noreply, socket}
550550
end
551551

552+
defp job_opts(socket) do
553+
case socket.assigns.job.location do
554+
"US-NY" -> [location: "east coast"]
555+
_ -> []
556+
end
557+
end
558+
552559
defp assign_applicants(socket) do
553560
all_applicants = Jobs.list_job_applications(socket.assigns.job)
554561

555562
# Get total matches count first (efficient query)
556-
total_matches_count = Settings.get_job_matches_count(socket.assigns.job)
563+
total_matches_count = Settings.get_job_matches_count(socket.assigns.job, job_opts(socket))
557564

558565
# Load 12 matches for sorting by contributions
559-
all_matches = Settings.get_job_matches(socket.assigns.job, limit: 12)
566+
all_matches = Settings.get_job_matches(socket.assigns.job, job_opts(socket) ++ [limit: 12])
560567

561568
developers =
562569
all_matches

0 commit comments

Comments
 (0)