]> git.openstreetmap.org Git - rails.git/blobdiff - app/models/trace.rb
Add index on gpx_files table on user_id, id
[rails.git] / app / models / trace.rb
index 818cc363b8629595bed5a4d842033f708598f14c..9768c0538bbb58abe138cb58e6b57d71f3276de7 100644 (file)
@@ -2,11 +2,11 @@
 #
 # Table name: gpx_files
 #
 #
 # Table name: gpx_files
 #
-#  id          :bigint(8)        not null, primary key
-#  user_id     :bigint(8)        not null
+#  id          :bigint           not null, primary key
+#  user_id     :bigint           not null
 #  visible     :boolean          default(TRUE), not null
 #  name        :string           default(""), not null
 #  visible     :boolean          default(TRUE), not null
 #  name        :string           default(""), not null
-#  size        :bigint(8)
+#  size        :bigint
 #  latitude    :float
 #  longitude   :float
 #  timestamp   :datetime         not null
 #  latitude    :float
 #  longitude   :float
 #  timestamp   :datetime         not null
 #
 # Indexes
 #
 #
 # Indexes
 #
-#  gpx_files_timestamp_idx           (timestamp)
-#  gpx_files_user_id_idx             (user_id)
-#  gpx_files_visible_visibility_idx  (visible,visibility)
+#  gpx_files_timestamp_idx            (timestamp)
+#  gpx_files_user_id_idx              (user_id)
+#  gpx_files_visible_visibility_idx   (visible,visibility)
+#  index_gpx_files_on_user_id_and_id  (user_id,id)
 #
 # Foreign Keys
 #
 #
 # Foreign Keys
 #
@@ -38,6 +39,7 @@ class Trace < ApplicationRecord
   scope :visible_to, ->(u) { visible.where(:visibility => %w[public identifiable]).or(visible.where(:user => u)) }
   scope :visible_to_all, -> { where(:visibility => %w[public identifiable]) }
   scope :tagged, ->(t) { joins(:tags).where(:gpx_file_tags => { :tag => t }) }
   scope :visible_to, ->(u) { visible.where(:visibility => %w[public identifiable]).or(visible.where(:user => u)) }
   scope :visible_to_all, -> { where(:visibility => %w[public identifiable]) }
   scope :tagged, ->(t) { joins(:tags).where(:gpx_file_tags => { :tag => t }) }
+  scope :imported, -> { where(:inserted => true) }
 
   has_one_attached :file, :service => Settings.trace_file_storage
   has_one_attached :image, :service => Settings.trace_image_storage
 
   has_one_attached :file, :service => Settings.trace_file_storage
   has_one_attached :image, :service => Settings.trace_image_storage
@@ -80,16 +82,16 @@ class Trace < ApplicationRecord
             :content_type => content_type(attachable.path),
             :identify => false)
     else
             :content_type => content_type(attachable.path),
             :identify => false)
     else
-      super(attachable)
+      super
     end
   end
 
   def public?
     end
   end
 
   def public?
-    visibility == "public" || visibility == "identifiable"
+    %w[public identifiable].include?(visibility)
   end
 
   def trackable?
   end
 
   def trackable?
-    visibility == "trackable" || visibility == "identifiable"
+    %w[trackable identifiable].include?(visibility)
   end
 
   def identifiable?
   end
 
   def identifiable?