From cdb42d2a6ce539be3f3e50edebb88240dfd16e04 Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Wed, 7 Nov 2018 08:57:14 +0000 Subject: [PATCH] Avoid ordering points from public and private traces Closes #2046 --- Gemfile | 1 + Gemfile.lock | 15 +++++++++------ app/controllers/api_controller.rb | 4 +++- app/models/concerns/geo_record.rb | 2 +- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/Gemfile b/Gemfile index 05bfc6cbd..249a8ca19 100644 --- a/Gemfile +++ b/Gemfile @@ -44,6 +44,7 @@ gem "autoprefixer-rails", "~> 8.6.3" gem "image_optim_rails" # Load rails plugins +gem "active_record_union" gem "actionpack-page_caching" gem "cancancan" gem "composite_primary_keys", "~> 11.0.0" diff --git a/Gemfile.lock b/Gemfile.lock index 72f769929..6472d586a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -29,6 +29,8 @@ GEM erubi (~> 1.4) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.3) + active_record_union (1.3.0) + activerecord (>= 4.0) activejob (5.2.0) activesupport (= 5.2.0) globalid (>= 0.3.6) @@ -66,7 +68,7 @@ GEM bootsnap (1.3.2) msgpack (~> 1.0) builder (3.2.3) - cancancan (2.1.3) + cancancan (2.3.0) canonical-rails (0.2.4) rails (>= 4.1, < 5.3) capybara (2.18.0) @@ -88,7 +90,7 @@ GEM coffee-script-source (1.12.2) composite_primary_keys (11.0.3) activerecord (~> 5.2.0) - concurrent-ruby (1.0.5) + concurrent-ruby (1.1.3) coveralls (0.8.22) json (>= 1.8, < 3) simplecov (~> 0.16.1) @@ -177,7 +179,7 @@ GEM mini_mime (>= 0.1.1) marcel (0.3.3) mimemagic (~> 0.3.2) - method_source (0.9.0) + method_source (0.9.1) mime-types (3.2.2) mime-types-data (~> 3.2015) mime-types-data (3.2018.0812) @@ -255,7 +257,7 @@ GEM puma (3.12.0) quad_tile (1.0.1) r2 (0.2.7) - rack (2.0.5) + rack (2.0.6) rack-cors (1.0.2) rack-openid (1.3.1) rack (>= 1.1.0) @@ -346,7 +348,7 @@ GEM actionpack (>= 4.0) activesupport (>= 4.0) sprockets (>= 3.0.0) - term-ansicolor (1.6.0) + term-ansicolor (1.7.0) tins (~> 1.0) terrapin (0.6.0) climate_control (>= 0.0.3, < 1.0) @@ -356,7 +358,7 @@ GEM thor (0.19.4) thread_safe (0.3.6) tilt (2.0.8) - tins (1.17.0) + tins (1.18.0) tzinfo (1.2.5) thread_safe (~> 0.1) uglifier (4.1.19) @@ -382,6 +384,7 @@ DEPENDENCIES SystemTimer (>= 1.1.3) aasm actionpack-page_caching + active_record_union annotate autoprefixer-rails (~> 8.6.3) better_errors diff --git a/app/controllers/api_controller.rb b/app/controllers/api_controller.rb index 81b8bca53..d97feace2 100644 --- a/app/controllers/api_controller.rb +++ b/app/controllers/api_controller.rb @@ -30,7 +30,9 @@ class ApiController < ApplicationController end # get all the points - points = Tracepoint.bbox(bbox).offset(offset).limit(TRACEPOINTS_PER_PAGE).order("gpx_id DESC, trackid ASC, timestamp ASC") + ordered_points = Tracepoint.bbox(bbox).joins(:trace).where(:gpx_files => { :visibility => %w[trackable identifiable] }).order("gpx_id DESC, trackid ASC, timestamp ASC") + unordered_points = Tracepoint.bbox(bbox).joins(:trace).where(:gpx_files => { :visibility => %w[public private] }).order("gps_points.latitude", "gps_points.longitude", "gps_points.timestamp") + points = ordered_points.union_all(unordered_points).offset(offset).limit(TRACEPOINTS_PER_PAGE) doc = XML::Document.new doc.encoding = XML::Encoding::UTF_8 diff --git a/app/models/concerns/geo_record.rb b/app/models/concerns/geo_record.rb index 06049c295..dbda2960f 100644 --- a/app/models/concerns/geo_record.rb +++ b/app/models/concerns/geo_record.rb @@ -22,7 +22,7 @@ module GeoRecord SCALE = 10000000 included do - scope :bbox, ->(bbox) { where(OSM.sql_for_area(bbox)) } + scope :bbox, ->(bbox) { where(OSM.sql_for_area(bbox, "#{table_name}.")) } before_save :update_tile end -- 2.43.2