Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
V
VeNJob
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tô Ngọc Ánh
VeNJob
Commits
148f59aa
Commit
148f59aa
authored
Aug 03, 2020
by
Tô Ngọc Ánh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor code to improve performance
parent
6292354d
Pipeline
#776
failed with stages
in 0 seconds
Changes
7
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
14 additions
and
22 deletions
+14
-22
app/controllers/home_controller.rb
+1
-1
app/controllers/locations_controller.rb
+2
-2
app/models/industry.rb
+2
-5
app/models/location.rb
+4
-6
app/views/industries/_industry.html.erb
+1
-3
app/views/locations/_city.html.erb
+2
-3
app/views/locations/index.html.erb
+2
-2
No files found.
app/controllers/home_controller.rb
View file @
148f59aa
...
@@ -3,7 +3,7 @@ class HomeController < ApplicationController
...
@@ -3,7 +3,7 @@ class HomeController < ApplicationController
@total_jobs
=
Job
.
count
@total_jobs
=
Job
.
count
@locations
=
Location
.
select
(
:id
,
:city
)
@locations
=
Location
.
select
(
:id
,
:city
)
@industries
=
Industry
.
select
(
:id
,
:name
)
@industries
=
Industry
.
select
(
:id
,
:name
)
@jobs
=
Job
.
order
(
created_at: :desc
).
limit
(
Job
::
NUMBER_LATEST_JOB
)
@jobs
=
Job
.
includes
(
:company
,
:locations
).
order
(
created_at: :desc
).
limit
(
Job
::
NUMBER_LATEST_JOB
)
@top_cities
=
Location
.
top_locations
(
9
)
@top_cities
=
Location
.
top_locations
(
9
)
@top_industries
=
Industry
.
top_industries
(
9
)
@top_industries
=
Industry
.
top_industries
(
9
)
end
end
...
...
app/controllers/locations_controller.rb
View file @
148f59aa
class
LocationsController
<
ApplicationController
class
LocationsController
<
ApplicationController
def
index
def
index
@vn_cities_lists
=
Location
.
vietnam
@vn_cities_lists
=
Location
.
vietnam
.
count_job
@internal_cities_lists
=
Location
.
international
@internal_cities_lists
=
Location
.
international
.
count_job
end
end
end
end
app/models/industry.rb
View file @
148f59aa
class
Industry
<
ApplicationRecord
class
Industry
<
ApplicationRecord
scope
:top_industries
,
->
(
number
)
{
joins
(
:jobs
)
scope
:count_job
,
->
{
joins
(
:jobs
).
group
(
:industry_id
).
select
(
'industries.*, count(jobs.id) as job_count'
)
}
.
group
(
:industry_id
)
scope
:top_industries
,
->
(
number
)
{
count_job
.
order
(
Arel
.
sql
(
'count(jobs.id) DESC'
)).
limit
(
number
)
}
.
order
(
Arel
.
sql
(
'count(jobs.id) DESC'
))
.
take
(
number
)
}
has_and_belongs_to_many
:jobs
has_and_belongs_to_many
:jobs
end
end
app/models/location.rb
View file @
148f59aa
class
Location
<
ApplicationRecord
class
Location
<
ApplicationRecord
scope
:top_locations
,
->
(
number
)
{
joins
(
:jobs
)
scope
:count_job
,
->
{
joins
(
:jobs
).
group
(
:location_id
).
select
(
'locations.*, count(jobs.id) as job_count'
)
}
.
group
(
:location_id
)
scope
:top_locations
,
->
(
number
)
{
count_job
.
order
(
Arel
.
sql
(
'job_count DESC'
)).
limit
(
number
)
}
.
order
(
Arel
.
sql
(
'count(jobs.id) DESC'
))
scope
:international
,
->
{
where
(
oversea:
true
)
}
.
take
(
number
)
}
scope
:vietnam
,
->
{
where
(
oversea:
false
)
}
scope
:international
,
->
{
where
(
oversea:
true
)
}
scope
:vietnam
,
->
{
where
(
oversea:
false
)
}
CITY_VIETNAM_NUMBER
=
70
CITY_VIETNAM_NUMBER
=
70
...
...
app/views/industries/_industry.html.erb
View file @
148f59aa
<%
if
industry
.
jobs
.
size
.
positive?
%>
<div
class=
'col-4 my-2'
>
<div
class=
'col-4 my-2'
>
<div
class=
'card'
>
<div
class=
'card'
>
<%=
link_to
'#'
,
class:
'card-body text-decoration-none'
do
%>
<%=
link_to
'#'
,
class:
'card-body text-decoration-none'
do
%>
<h5
class=
'card-title font-weight-bold'
>
<%=
industry
.
name
%>
</h5>
<h5
class=
'card-title font-weight-bold'
>
<%=
industry
.
name
%>
</h5>
<p
class=
'card-text'
>
<%=
industry
.
job
s
.
size
%>
Jobs
</p>
<p
class=
'card-text'
>
<%=
industry
.
job
_count
%>
Jobs
</p>
<%
end
%>
<%
end
%>
</div>
</div>
</div>
</div>
<%
end
%>
app/views/locations/_city.html.erb
View file @
148f59aa
<%
if
location
.
jobs
.
size
.
positive?
%>
<div
class=
'col-4 my-2'
>
<div
class=
'col-4 my-2'
>
<div
class=
'card'
>
<div
class=
'card'
>
<%=
link_to
'#'
,
class:
'card-body text-decoration-none'
do
%>
<%=
link_to
'#'
,
class:
'card-body text-decoration-none'
do
%>
<h5
class=
'card-title font-weight-bold'
>
<%=
location
.
city
%>
</h5>
<h5
class=
'card-title font-weight-bold'
>
<%=
location
.
city
%>
</h5>
<p
class=
'card-text'
>
<%=
location
.
job
s
.
size
%>
Jobs
</p>
<p
class=
'card-text'
>
<%=
location
.
job
_count
%>
Jobs
</p>
<%
end
%>
<%
end
%>
</div>
</div>
</div>
</div>
\ No newline at end of file
<%
end
%>
app/views/locations/index.html.erb
View file @
148f59aa
...
@@ -4,11 +4,11 @@
...
@@ -4,11 +4,11 @@
<ul
class=
'list-group list-group-horizontal'
>
<ul
class=
'list-group list-group-horizontal'
>
<li
class=
'list-group-item'
>
<li
class=
'list-group-item'
>
<a
href=
'#vietnam'
>
Việt Nam
</a>
<a
href=
'#vietnam'
>
Việt Nam
</a>
<span
class=
'badge badge-primary badge-pill'
>
<%=
@vn_cities_lists
.
size
%>
</span>
<span
class=
'badge badge-primary badge-pill'
>
<%=
@vn_cities_lists
.
length
%>
</span>
</li>
</li>
<li
class=
'list-group-item'
>
<li
class=
'list-group-item'
>
<a
href=
'#international'
>
International
</a>
<a
href=
'#international'
>
International
</a>
<span
class=
'badge badge-primary badge-pill'
>
<%=
@internal_cities_lists
.
size
%>
</span>
<span
class=
'badge badge-primary badge-pill'
>
<%=
@internal_cities_lists
.
length
%>
</span>
</li>
</li>
</ul>
</ul>
</div>
</div>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment