Merge pull request #3071 from evazion/fix-order-index
Fix #3000: order: metatags aren't indexed.
This commit is contained in:
@@ -78,7 +78,7 @@ private
|
||||
end
|
||||
|
||||
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
|
||||
respond_with(@posts) do |format|
|
||||
format.html {render :action => "index_by_post"}
|
||||
|
||||
@@ -392,34 +392,34 @@ class PostQueryBuilder
|
||||
relation = relation.order("posts.id DESC")
|
||||
|
||||
when "score", "score_desc"
|
||||
relation = relation.order("posts.score DESC")
|
||||
relation = relation.order("posts.score DESC, posts.id DESC")
|
||||
|
||||
when "score_asc"
|
||||
relation = relation.order("posts.score ASC")
|
||||
relation = relation.order("posts.score ASC, posts.id ASC")
|
||||
|
||||
when "favcount"
|
||||
relation = relation.order("posts.fav_count DESC")
|
||||
relation = relation.order("posts.fav_count DESC, posts.id DESC")
|
||||
|
||||
when "favcount_asc"
|
||||
relation = relation.order("posts.fav_count ASC")
|
||||
relation = relation.order("posts.fav_count ASC, posts.id ASC")
|
||||
|
||||
when "change", "change_desc"
|
||||
relation = relation.order("posts.updated_at DESC")
|
||||
relation = relation.order("posts.updated_at DESC, posts.id DESC")
|
||||
|
||||
when "change_asc"
|
||||
relation = relation.order("posts.updated_at ASC")
|
||||
relation = relation.order("posts.updated_at ASC, posts.id ASC")
|
||||
|
||||
when "comment", "comm"
|
||||
relation = relation.order("posts.last_commented_at DESC NULLS LAST")
|
||||
relation = relation.order("posts.last_commented_at DESC NULLS LAST, posts.id DESC")
|
||||
|
||||
when "comment_asc", "comm_asc"
|
||||
relation = relation.order("posts.last_commented_at ASC NULLS LAST")
|
||||
relation = relation.order("posts.last_commented_at ASC NULLS LAST, posts.id ASC")
|
||||
|
||||
when "comment_bumped"
|
||||
relation = relation.order("posts.last_comment_bumped_at DESC NULLS LAST")
|
||||
|
||||
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"
|
||||
relation = relation.order("posts.last_noted_at DESC NULLS LAST")
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
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"
|
||||
|
||||
execute "analyze posts"
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -6598,6 +6598,13 @@ CREATE INDEX index_forum_topic_visits_on_user_id ON forum_topic_visits USING btr
|
||||
CREATE INDEX index_forum_topics_on_creator_id ON forum_topics USING btree (creator_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_forum_topics_on_is_sticky_and_updated_at; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE INDEX index_forum_topics_on_is_sticky_and_updated_at ON forum_topics USING btree (is_sticky, updated_at);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_forum_topics_on_text_index; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
@@ -6889,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: -
|
||||
--
|
||||
|
||||
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: -
|
||||
--
|
||||
|
||||
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);
|
||||
|
||||
|
||||
--
|
||||
@@ -7536,3 +7543,7 @@ INSERT INTO schema_migrations (version) VALUES ('20170428220448');
|
||||
|
||||
INSERT INTO schema_migrations (version) VALUES ('20170512221200');
|
||||
|
||||
INSERT INTO schema_migrations (version) VALUES ('20170515235205');
|
||||
|
||||
INSERT INTO schema_migrations (version) VALUES ('20170519204506');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user