Skip to content

Commit

Permalink
refactor: Update job skills in update_skills.py
Browse files Browse the repository at this point in the history
This commit improves the efficiency of the `update_skills.py` script by optimizing the process of updating job skills. Instead of iterating over all skills for each job, the script now fetches all jobs and skills once to avoid repeated database hits. It also uses a query to find matching jobs based on skill names in their descriptions and adds the skills to those jobs. This change reduces the number of database queries and improves the overall performance of the script.
  • Loading branch information
QA2A committed Sep 8, 2024
1 parent c808db2 commit f1b1575
Show file tree
Hide file tree
Showing 2 changed files with 126 additions and 107 deletions.
219 changes: 115 additions & 104 deletions website/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,35 @@
{% load static %}
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
{% block seo_header %}
<title>{% block title %}Pingojo - Crowd-Powered Hiring {% endblock %}</title>
<meta name="description"
content="{% block description %}Pingojo: Match jobs with a tap! 🚀 Keep tabs on your network 📊 and privacy 🛡️ in one fun, fast spot. Join the recruitment revolution! 🎯🥳{% endblock %}">
<meta name="keywords"
content="Pingojo, recruitment platform, job seekers, recruiters, companies, job matching, virtual recruitment, contact management, real-time dashboard">
{% endblock %}

<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>

<link id="favicon" rel="icon" type="image/png" href="/static/img/logo.png">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.1.0/css/all.min.css"
crossorigin="anonymous">
<link rel="stylesheet" href="{% static 'css/base.css' %}">
<script src="{% static 'js/favicon-updater.js' %}"></script>
<script src="https://unpkg.com/htmx.org@1.6.1"></script>
{% if production %}
<script src="https://js.sentry-cdn.com/d824685ec54f3b0cab6e256b814efbb7.min.js" crossorigin="anonymous"></script>
{% endif %}

{% block extra_css %}

{% endblock %}
{% block extra_head %}
{% endblock %}

</head>

<body>
<style>

<head>
<meta charset="UTF-8">
{% block seo_header %}
<title>
{% block title %}Pingojo - Crowd-Powered Hiring{% endblock %}
</title>
<meta name="description"
content="{% block description %}Pingojo: Match jobs with a tap! 🚀 Keep tabs on your network 📊 and privacy 🛡️ in one fun, fast spot. Join the recruitment revolution! 🎯🥳{% endblock %}">
<meta name="keywords"
content="Pingojo, recruitment platform, job seekers, recruiters, companies, job matching, virtual recruitment, contact management, real-time dashboard">
{% endblock %}
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
<link id="favicon" rel="icon" type="image/png" href="/static/img/logo.png">
<link rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.1.0/css/all.min.css"
crossorigin="anonymous">
<link rel="stylesheet" href="{% static 'css/base.css' %}">
<script src="{% static 'js/favicon-updater.js' %}"></script>
<script src="https://unpkg.com/htmx.org@1.6.1"></script>
{% if production %}
<script src="https://js.sentry-cdn.com/d824685ec54f3b0cab6e256b814efbb7.min.js"
crossorigin="anonymous"></script>
{% endif %}
{% block extra_css %}{% endblock %}
{% block extra_head %}{% endblock %}
</head>
<body>
<style>
header {
background-color: #fff;
position: sticky;
Expand Down Expand Up @@ -71,21 +65,30 @@
}
}
</style>
<header style="padding:0px; margin:0px; padding-top:10px; padding-bottom:10px;">


{% block logo %}
<span style="font-size: 40px; font-weight: bold; margin-left:10px;">
<div style="display: flex; flex-direction: column; align-items: center;">
<a href="/" style="color: black; text-decoration: none; line-height: 0px;">
<img src="{% static 'svg/logo-black.svg' %}" alt="Pingojo Logo" style="margin:0px;padding:0px;">
<header style="padding:0px;
margin:0px;
padding-top:10px;
padding-bottom:10px">
{% block logo %}
<span style="font-size: 40px; font-weight: bold; margin-left:10px;">
<div style="display: flex; flex-direction: column; align-items: center;">
<a href="/"
style="color: black;
text-decoration: none;
line-height: 0px">
<img src="{% static 'svg/logo-black.svg' %}"
alt="Pingojo Logo"
style="margin:0px;
padding:0px">
</a>
<small style="color: black; margin-top: 0px; margin-left:51px; font-size: 12px;">Say goodbye to no-reply</small>
</div>
</span>
{% endblock %}

<style>
<small style="color: black;
margin-top: 0px;
margin-left:51px;
font-size: 12px">Say goodbye to no-reply</small>
</div>
</span>
{% endblock %}
<style>
.auth-buttons {
display: flex;
align-items: center;
Expand Down Expand Up @@ -148,25 +151,53 @@
animation-delay: 2s; /* This delay will keep the message visible for 2 seconds before fading out */
}

</style>

<div class="auth-buttons">
<form method="get" action="{% url 'jobs_list' %}" class="search-form-company">
<input type="text" placeholder="Search..." name="search" value="{{request.GET.search|default:''}}" required class="search-input" style="height:36px;">
<button class="login-btn search-btn" style="background-color: #000000;">Search</button>
</style>
<div class="auth-buttons">
<form method="get"
action="{% url 'jobs_list' %}"
class="search-form-company">
<!-- Dropdown for search type -->
<select name="search_type"
class="search-type-select"
style="height: 36px;
border-radius: 5px 0 0 5px;
border: 1px solid #ccc">
<option value="company"
{% if request.GET.search_type == "company" or not request.GET.search_type %}selected{% endif %}>
Company
</option>
<option value="skill"
{% if request.GET.search_type == "skill" %}selected{% endif %}>Skill</option>
</select>
<!-- Search input -->
<input type="text"
placeholder="Search..."
name="search"
value="{{ request.GET.search|default:'' }}"
required
class="search-input"
style="height:36px;
border-left:none">
<!-- Search button -->
<button class="login-btn search-btn" style="background-color: #000000;">Search</button>
</form>

<a href="{% url 'job_add' %}" class="login-btn" style="background-color: green;">Post a Job</a>


<a id="login-logout" href="" class="login-btn" style="background-color: red;">Logout</a>
<a id="profileIcon" href="#" style="display: none; font-size:35px; margin-right:30px; color:dodgerblue;">
<a href="{% url 'job_add' %}"
class="login-btn"
style="background-color: green">Post a Job</a>
<a id="login-logout"
href=""
class="login-btn"
style="background-color: red">Logout</a>
<a id="profileIcon"
href="#"
style="display: none;
font-size:35px;
margin-right:30px;
color:dodgerblue">
<i class="fas fa-user"></i>
</a>

</div>

<script>
</div>
<script>
window.onload = function() {
fetch('/api/is_authenticated')
.then(response => response.json())
Expand Down Expand Up @@ -207,11 +238,10 @@
loadTimeElement.innerHTML = formattedLoadTime + "ms";
}
}
</script>

<!-- TODO: make these messages fade away nicely after 2 seconds, and make them a bounce in and out with an effect -->
</header>
<style>
</script>
<!-- TODO: make these messages fade away nicely after 2 seconds, and make them a bounce in and out with an effect -->
</header>
<style>
.messages {
margin-top:20px;
position: fixed;
Expand All @@ -231,24 +261,14 @@



</style>


{% if messages %}
<div class="messages">
{% for message in messages %}
<div class="alert-{{ message.tags }}" style="margin:0px;">
{{ message }}
</div>
{% endfor %}
</div>
{% endif %}



{% block content %}
{% endblock %}
<style>
</style>
{% if messages %}
<div class="messages">
{% for message in messages %}<div class="alert-{{ message.tags }}" style="margin:0px;">{{ message }}</div>{% endfor %}
</div>
{% endif %}
{% block content %}{% endblock %}
<style>

footer {
background-color: #000;
Expand Down Expand Up @@ -282,12 +302,8 @@
}


</style>




<script>
</style>
<script>
window.onscroll = function() {
var footer = document.querySelector('footer');

Expand Down Expand Up @@ -334,14 +350,9 @@
mf.src = "//cdn.mouseflow.com/projects/75696671-ed61-4656-9ca3-1a503dc1d0b1.js";
document.getElementsByTagName("head")[0].appendChild(mf);
})();
</script>
{% block extra_js %}

{% endblock %}

{% block script %}

{% endblock %}
</body>

</script>
{% block extra_js %}
{% endblock %}
{% block script %}{% endblock %}
</body>
</html>
14 changes: 11 additions & 3 deletions website/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -677,11 +677,18 @@ def dispatch(self, *args, **kwargs):

def get_queryset(self):
if not self.queryset:
search_type = self.request.GET.get("search_type", "").strip()
search_query = re.sub(
r"[^a-zA-Z0-9,. ]", "", self.request.GET.get("search", "").strip()
)

if search_query:
if search_type == "skill":
# If search_type is 'skill', return jobs matching the skill
skill_name = search_query
self.queryset = Job.objects.filter(skills__name__icontains=skill_name).select_related("company", "role").distinct()

elif search_query:
# For general search query
query = SearchQuery(search_query)
queryset = (
Job.objects.select_related("company", "role")
Expand All @@ -695,10 +702,10 @@ def get_queryset(self):
job_count = self.queryset.count()
search = Search(query=search_query, matched_job_count=job_count)
search.save()
# send_slack_notification(search)
else:
self.queryset = Job.objects.select_related("company", "role").all()
else:
# Default queryset if no search term is provided
self.queryset = Job.objects.select_related("company", "role").order_by(
F("posted_date").desc(nulls_last=True)
)
Expand All @@ -716,7 +723,7 @@ def get_queryset(self):
applied_jobs = Application.objects.filter(
user=self.request.user
).values_list("job_id", flat=True)
queryset = self.queryset.exclude(id__in=applied_jobs)
self.queryset = self.queryset.exclude(id__in=applied_jobs)

ordering = self.request.GET.get("ordering")
if ordering and ordering.lstrip("-") in [
Expand Down Expand Up @@ -752,6 +759,7 @@ def get_context_data(self, **kwargs):
return context



class SourceListView(ListView):
model = Source
template_name = "sources.html"
Expand Down

0 comments on commit f1b1575

Please sign in to comment.