Make changeset#query preload users, tags and comments
authorTom Hughes <tom@compton.nu>
Mon, 4 Dec 2017 07:54:19 +0000 (07:54 +0000)
committerTom Hughes <tom@compton.nu>
Mon, 4 Dec 2017 07:54:19 +0000 (07:54 +0000)
app/controllers/changeset_controller.rb
app/models/changeset.rb

index 898afae..8fbbe13 100644 (file)
@@ -216,6 +216,12 @@ class ChangesetController < ApplicationController
     changesets = conditions_closed(changesets, params["closed"])
     changesets = conditions_ids(changesets, params["changesets"])
 
+    # sort and limit the changesets
+    changesets = changesets.order("created_at DESC").limit(100)
+
+    # preload users, tags and comments
+    changesets = changesets.preload(:user, :changeset_tags, :comments)
+
     # create the results document
     results = OSM::API.new.get_xml_doc
 
index 37d26e0..2ec26ec 100644 (file)
@@ -238,7 +238,7 @@ class Changeset < ActiveRecord::Base
 
     bbox.to_unscaled.add_bounds_to(el1, "_") if bbox.complete?
 
-    el1["comments_count"] = comments.count.to_s
+    el1["comments_count"] = comments.length.to_s
 
     if include_discussion
       el2 = XML::Node.new("discussion")