]> git.openstreetmap.org Git - rails.git/commitdiff
Avoid ordering points from public and private traces
authorTom Hughes <tom@compton.nu>
Wed, 7 Nov 2018 08:57:14 +0000 (08:57 +0000)
committerTom Hughes <tom@compton.nu>
Wed, 7 Nov 2018 08:57:14 +0000 (08:57 +0000)
Closes #2046

Gemfile
Gemfile.lock
app/controllers/api_controller.rb
app/models/concerns/geo_record.rb

diff --git a/Gemfile b/Gemfile
index 05bfc6cbd3e6d14ea36f335a468cf6767038de70..249a8ca19a325c52fea3b598482b63a9ce45442a 100644 (file)
--- 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"
index 72f769929033edf0790dbfe20be7567cfda32b40..6472d586ac1667e25ddb628a839e513553ad666e 100644 (file)
@@ -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
index 81b8bca5323f3cbe33bb1a2c990679b8a9ca5cce..d97feace24d748afa86be812e582493561818d62 100644 (file)
@@ -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
index 06049c2951b25876999cc7e3ee0fc070bacd97e6..dbda2960f65ce6ad72d7eaf996b9bbee76fc57e0 100644 (file)
@@ -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