Skip to content

Commit 270595e

Browse files
committed
feat: dynamic job matching
1 parent 49e7695 commit 270595e

File tree

3 files changed

+52
-6
lines changed

3 files changed

+52
-6
lines changed

lib/algora/settings/settings.ex

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ defmodule Algora.Settings do
22
@moduledoc false
33
use Ecto.Schema
44

5+
import Ecto.Query
6+
57
alias Algora.Accounts
8+
alias Algora.Accounts.User
69
alias Algora.Repo
710

811
@primary_key {:key, :string, []}
@@ -91,10 +94,37 @@ defmodule Algora.Settings do
9194
set("org_matches:#{org_handle}", %{"matches" => matches})
9295
end
9396

94-
def get_job_matches(job_id) do
95-
case get("job_matches:#{job_id}") do
96-
%{"matches" => matches} when is_list(matches) -> load_matches(matches)
97-
_ -> []
97+
def get_job_matches(job) do
98+
case get("job_matches:#{job.id}") do
99+
%{"matches" => matches} when is_list(matches) ->
100+
load_matches(matches)
101+
102+
_ ->
103+
[
104+
tech_stack: job.tech_stack,
105+
limit: 50,
106+
users: apply_job_criteria(User, get_job_criteria(job.id))
107+
]
108+
|> Algora.Cloud.list_top_matches()
109+
|> load_matches_2()
110+
end
111+
end
112+
113+
def apply_job_criteria(query, criteria) do
114+
Enum.reduce(criteria, query, fn
115+
{"country", country}, query ->
116+
from([u] in query, where: u.country == ^country)
117+
end)
118+
end
119+
120+
def set_job_criteria(job_id, criteria) when is_binary(job_id) and is_map(criteria) do
121+
set("job_criteria:#{job_id}", %{"criteria" => criteria})
122+
end
123+
124+
def get_job_criteria(job_id) do
125+
case get("job_criteria:#{job_id}") do
126+
%{"criteria" => criteria} when is_map(criteria) -> criteria
127+
_ -> %{}
98128
end
99129
end
100130

@@ -145,6 +175,22 @@ defmodule Algora.Settings do
145175
end)
146176
end
147177

178+
def load_matches_2(matches) do
179+
user_map =
180+
[ids: Enum.map(matches, & &1[:user_id]), limit: :infinity]
181+
|> Accounts.list_developers()
182+
|> Enum.filter(& &1.provider_login)
183+
|> Map.new(fn user -> {user.id, user} end)
184+
185+
Enum.flat_map(matches, fn match ->
186+
if user = Map.get(user_map, match[:user_id]) do
187+
[%{user: user, contribution_score: match["contribution_score"]}]
188+
else
189+
[]
190+
end
191+
end)
192+
end
193+
148194
def get_blocked_users do
149195
case get("blocked_users") do
150196
%{"handles" => handles} when is_list(handles) -> handles

lib/algora_web/live/org/job_live.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -832,7 +832,7 @@ defmodule AlgoraWeb.Org.JobLive do
832832
all_applicants = Jobs.list_job_applications(socket.assigns.job)
833833
applicants = Enum.reject(all_applicants, & &1.imported_at)
834834
imports = Enum.filter(all_applicants, & &1.imported_at)
835-
matches = Settings.get_job_matches(socket.assigns.job.id)
835+
matches = Settings.get_job_matches(socket.assigns.job)
836836

837837
developers = matches |> Enum.concat(all_applicants) |> Enum.map(& &1.user)
838838

lib/algora_web/live/org/jobs_live.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ defmodule AlgoraWeb.Org.JobsLive do
4141
])
4242
}>
4343
<h2 class="font-display text-3xl font-semibold tracking-tight text-foreground sm:text-6xl mb-2">
44-
Jobs
44+
Join {@current_org.name}
4545
</h2>
4646
<p class="font-medium text-base text-muted-foreground">
4747
Open positions at {@current_org.name}

0 commit comments

Comments
 (0)