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
0
Merge Requests
0
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
Mai Hoang Thai Ha
VenJob
Commits
9d46edb2
Commit
9d46edb2
authored
Aug 10, 2021
by
Mai Hoang Thai Ha
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed n+1 query jobs#index
parent
7204d6e1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
6 additions
and
7 deletions
+6
-7
app/controllers/jobs_controller.rb
+2
-2
app/controllers/top_controller.rb
+1
-1
app/models/job.rb
+2
-2
app/views/jobs/index.html.slim
+1
-2
No files found.
app/controllers/jobs_controller.rb
View file @
9d46edb2
...
...
@@ -3,7 +3,7 @@ class JobsController < ApplicationController
if
job_params
.
present?
search
else
@jobs
=
Job
.
includes
(
:company
,
:cities_jobs
,
:cities
)
.
page
(
params
[
:page
]).
per
(
Job
::
JOB_PER_PAGE
)
@jobs
=
Job
.
sort_by_date
.
page
(
params
[
:page
]).
per
(
Job
::
JOB_PER_PAGE
)
end
end
...
...
@@ -17,7 +17,7 @@ class JobsController < ApplicationController
if
job_params
.
key?
(
:model
)
&&
job_params
.
key?
(
:slug
)
# search by model
model
=
params
[
:model
].
classify
.
constantize
@target
=
model
.
find_by
(
slug:
job_params
[
:slug
])
@jobs
=
@target
.
jobs
.
includes
(
:company
,
:cities_jobs
,
:cities
)
.
page
(
params
[
:page
]).
per
(
Job
::
JOB_PER_PAGE
)
@jobs
=
@target
.
jobs
.
sort_by_date
.
page
(
params
[
:page
]).
per
(
Job
::
JOB_PER_PAGE
)
end
end
...
...
app/controllers/top_controller.rb
View file @
9d46edb2
class
TopController
<
ApplicationController
def
index
@total_job
=
Job
.
count
@latest_jobs
=
Job
.
latest
@latest_jobs
=
Job
.
sort_by_date
.
limit
(
Job
::
LATEST_JOBS_LIMIT
)
@top_cities
=
City
.
top_jobs
@top_industries
=
Industry
.
top_jobs
end
...
...
app/models/job.rb
View file @
9d46edb2
...
...
@@ -9,7 +9,7 @@ class Job < ApplicationRecord
has_many
:favorite_jobs
,
dependent: :destroy
has_many
:history_job
,
dependent: :destroy
def
self
.
latest
joins
(
:cities
).
includes
(
:cities
,
:cities_jobs
,
:company
).
order
(
created_at: :desc
)
.
limit
(
LATEST_JOBS_LIMIT
)
def
self
.
sort_by_date
joins
(
:cities
).
includes
(
:cities
,
:cities_jobs
,
:company
).
order
(
created_at: :desc
)
end
end
app/views/jobs/index.html.slim
View file @
9d46edb2
...
...
@@ -21,8 +21,7 @@
p
.job-salary.text-success
|
Salary:
#{
job
.
salary
}
ul
.list-unstyled
-
city_list
=
job
.
cities
=
show_location
(
city_list
)
=
show_location
(
job
.
cities
)
.job-desc
=
truncate
(
simple_format
(
job
.
description
),
escape:
false
,
length:
250
)
hr
.my-4
...
...
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