diff --git a/app/logical/post_query_builder.rb b/app/logical/post_query_builder.rb index 45165f3ee..80e22a43c 100644 --- a/app/logical/post_query_builder.rb +++ b/app/logical/post_query_builder.rb @@ -64,6 +64,7 @@ class PostQueryBuilder ORDER_METATAGS = %w[ id id_desc + md5 md5_asc score score_asc favcount favcount_asc created_at created_at_asc @@ -81,6 +82,7 @@ class PostQueryBuilder modqueue random custom + none ] + COUNT_METATAGS + COUNT_METATAG_SYNONYMS.flat_map { |str| [str, "#{str}_asc"] } + @@ -561,6 +563,12 @@ class PostQueryBuilder when "id_desc" relation = relation.order("posts.id DESC") + when "md5", "md5_desc" + relation = relation.order("posts.md5 DESC") + + when "md5_asc" + relation = relation.order("posts.md5 ASC") + when "score", "score_desc" relation = relation.order("posts.score DESC, posts.id DESC") @@ -672,6 +680,9 @@ class PostQueryBuilder when "modqueue_asc" relation = relation.left_outer_joins(:flags).order(Arel.sql("GREATEST(posts.created_at, post_flags.created_at) ASC, posts.id ASC")) + when "none" + relation = relation.reorder(nil) + else relation = relation.order("posts.id DESC") end diff --git a/test/unit/post_query_builder_test.rb b/test/unit/post_query_builder_test.rb index 8922c8706..52c79350a 100644 --- a/test/unit/post_query_builder_test.rb +++ b/test/unit/post_query_builder_test.rb @@ -763,6 +763,7 @@ class PostQueryBuilderTest < ActiveSupport::TestCase p = create( :post, score: n, + md5: n.to_s, fav_count: n, file_size: 1.megabyte * n, # posts[0] is portrait, posts[1] is landscape. posts[1].mpixels > posts[0].mpixels. @@ -801,6 +802,8 @@ class PostQueryBuilderTest < ActiveSupport::TestCase assert_tag_match(posts.reverse, "order:note_count_desc") assert_tag_match(posts.reverse, "order:notes") assert_tag_match(posts.reverse, "order:notes_desc") + assert_tag_match(posts.reverse, "order:md5") + assert_tag_match(posts.reverse, "order:md5_desc") assert_tag_match(posts, "order:id_asc") assert_tag_match(posts, "order:score_asc") @@ -820,6 +823,10 @@ class PostQueryBuilderTest < ActiveSupport::TestCase assert_tag_match(posts, "order:copytags_asc") assert_tag_match(posts, "order:note_count_asc") assert_tag_match(posts, "order:notes_asc") + assert_tag_match(posts, "order:md5_asc") + + # ordering is unpredictable so can't be tested. + assert_tag_match([posts.first], "id:#{posts.first.id} order:none") end should "return posts for order:comment_bumped" do