Open bex1 opened 7 years ago
See original commit (inlined below)👇
diff --git a/app/controllers/api/v1/jobs_controller.rb b/app/controllers/api/v1/jobs_controller.rb
index d2067cd..01ec49b 100644
--- a/app/controllers/api/v1/jobs_controller.rb
+++ b/app/controllers/api/v1/jobs_controller.rb
@@ -15,6 +15,23 @@ module Api
ALLOWED_INCLUDES = %w(owner company company.company_images language category hourly_pay comments).freeze # rubocop:disable Metrics/LineLength
+ def locations
+ authorize(Job)
+ data = Job.uncancelled.find_each(batch_size: 5000).map do |job|
+ {
+ id: job.id.to_s,
+ type: :jobs,
+ attributes: {
+ zip_latitude: job.zip_latitude,
+ zip_longitude: job.zip_longitude,
+ hours: job.hours
+ }
+ }
+ end
+
+ render json: { data: data }.to_json, status: :ok
+ end
+
api :GET, '/jobs', 'List jobs'
description 'Returns a list of jobs.'
ApipieDocHelper.params(self, Index::JobsIndex)
diff --git a/app/policies/job_policy.rb b/app/policies/job_policy.rb
index 80048a0..a8efbdd 100644
--- a/app/policies/job_policy.rb
+++ b/app/policies/job_policy.rb
@@ -30,6 +30,7 @@ class JobPolicy < ApplicationPolicy
true
end
+ alias_method :locations?, :index?
alias_method :show?, :index?
alias_method :google?, :show?
diff --git a/config/routes.rb b/config/routes.rb
index 6c78afd..122c468 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -17,6 +17,9 @@ Rails.application.routes.draw do
namespace :api do
namespace :v1 do
resources :jobs, param: :job_id, only: [:index, :show, :create, :update] do
+ collection do
+ get :locations, to: 'jobs#locations'
+ end
member do
get :matching_users, path: 'matching-users'
resources :job_comments, module: :jobs, path: :comments, only: [:index, :show, :create, :update, :destroy]
Running Rails development mode, on my machine, this returns ~1000 records in ~200ms (🐢) which isn't great but it will be enough for a while :)
I also tried increasing the max number of jobs on one page and limiting the number fields returned with GET /api/v1/jobs/fields[jobs]=zip_longitude,zip_latitude,name,job_date&page[size]=1000
, but that was really slow 🐢🐢🐢 it took ~1000ms 😴
Temporary fix is to allow a route to get all jobs with limited data fields to support the marker and the popup information window.
In the long run I think the best solution would be to have a route that can get a fixed max amount of jobs inside the map perimeter. When the perimeter is big (highly zoomed out) only one job should be returned from each cluster where markers overlap (jobs lie close) (so the markers dont overlap when zoomed out) One should then hint that if zooming in there may be more jobs to see etc.