search: fix order:note, order:comment_bumped to use indexes.
This commit is contained in:
@@ -78,7 +78,7 @@ private
|
|||||||
end
|
end
|
||||||
|
|
||||||
def index_by_post
|
def index_by_post
|
||||||
@posts = Post.where("last_comment_bumped_at IS NOT NULL").tag_match(params[:tags]).reorder("last_comment_bumped_at DESC").paginate(params[:page], :limit => 5, :search_count => params[:search])
|
@posts = Post.where("last_comment_bumped_at IS NOT NULL").tag_match(params[:tags]).reorder("last_comment_bumped_at DESC NULLS LAST").paginate(params[:page], :limit => 5, :search_count => params[:search])
|
||||||
@posts.each # hack to force rails to eager load
|
@posts.each # hack to force rails to eager load
|
||||||
respond_with(@posts) do |format|
|
respond_with(@posts) do |format|
|
||||||
format.html {render :action => "index_by_post"}
|
format.html {render :action => "index_by_post"}
|
||||||
|
|||||||
@@ -419,7 +419,7 @@ class PostQueryBuilder
|
|||||||
relation = relation.order("posts.last_comment_bumped_at DESC NULLS LAST")
|
relation = relation.order("posts.last_comment_bumped_at DESC NULLS LAST")
|
||||||
|
|
||||||
when "comment_bumped_asc"
|
when "comment_bumped_asc"
|
||||||
relation = relation.order("posts.last_comment_bumped_at ASC NULLS LAST")
|
relation = relation.order("posts.last_comment_bumped_at ASC NULLS FIRST")
|
||||||
|
|
||||||
when "note"
|
when "note"
|
||||||
relation = relation.order("posts.last_noted_at DESC NULLS LAST")
|
relation = relation.order("posts.last_noted_at DESC NULLS LAST")
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
class FixLastNotedAtIndexOnPosts < ActiveRecord::Migration
|
||||||
|
def up
|
||||||
|
Post.without_timeout do
|
||||||
|
remove_index :posts, column: :last_comment_bumped_at
|
||||||
|
add_index :posts, :last_comment_bumped_at, order: "DESC NULLS LAST"
|
||||||
|
|
||||||
|
remove_index :posts, column: :last_noted_at
|
||||||
|
add_index :posts, :last_noted_at, order: "DESC NULLS LAST"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -6896,14 +6896,14 @@ CREATE INDEX index_posts_on_image_width ON posts USING btree (image_width);
|
|||||||
-- Name: index_posts_on_last_comment_bumped_at; Type: INDEX; Schema: public; Owner: -
|
-- Name: index_posts_on_last_comment_bumped_at; Type: INDEX; Schema: public; Owner: -
|
||||||
--
|
--
|
||||||
|
|
||||||
CREATE INDEX index_posts_on_last_comment_bumped_at ON posts USING btree (last_comment_bumped_at);
|
CREATE INDEX index_posts_on_last_comment_bumped_at ON posts USING btree (last_comment_bumped_at DESC NULLS LAST);
|
||||||
|
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Name: index_posts_on_last_noted_at; Type: INDEX; Schema: public; Owner: -
|
-- Name: index_posts_on_last_noted_at; Type: INDEX; Schema: public; Owner: -
|
||||||
--
|
--
|
||||||
|
|
||||||
CREATE INDEX index_posts_on_last_noted_at ON posts USING btree (last_noted_at);
|
CREATE INDEX index_posts_on_last_noted_at ON posts USING btree (last_noted_at DESC NULLS LAST);
|
||||||
|
|
||||||
|
|
||||||
--
|
--
|
||||||
@@ -7545,3 +7545,5 @@ INSERT INTO schema_migrations (version) VALUES ('20170512221200');
|
|||||||
|
|
||||||
INSERT INTO schema_migrations (version) VALUES ('20170515235205');
|
INSERT INTO schema_migrations (version) VALUES ('20170515235205');
|
||||||
|
|
||||||
|
INSERT INTO schema_migrations (version) VALUES ('20170519204506');
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user