Skip to content

Commit

Permalink
FIX: order by op_likes leads to broken browsing
Browse files Browse the repository at this point in the history
  • Loading branch information
SamSaffron committed Dec 27, 2016
1 parent 744f1fd commit d28d8a1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 19 deletions.
24 changes: 6 additions & 18 deletions lib/freedom_patches/fast_pluck.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Speeds up #pluck so its about 2.2x faster, importantly makes pluck avoid creation of a slew
# of AR objects
#

require_dependency 'sql_builder'

Expand Down Expand Up @@ -34,22 +35,10 @@ class ActiveRecord::Relation
# end

class ::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
if Rails.version >= "4.2.0"
def select_raw(arel, name = nil, binds = [], &block)
arel, binds = binds_from_relation arel, binds
sql = to_sql(arel, binds)
execute_and_clear(sql, name, binds, &block)
end
else

def select_raw(arel, name = nil, binds = [], &block)
arel, binds = binds_from_relation arel, binds
sql = to_sql(arel, binds)

result = without_prepared_statement?(binds) ? exec_no_cache(sql, 'SQL', binds) :
exec_cache(sql, 'SQL', binds)
yield result, nil
end
def select_raw(arel, name = nil, binds = [], &block)
arel, binds = binds_from_relation arel, binds
sql = to_sql(arel, binds)
execute_and_clear(sql, name, binds, &block)
end
end

Expand All @@ -66,7 +55,6 @@ def pluck(*cols)
end
end


if has_include?(cols.first)
construct_relation_for_association_calculations.pluck(*cols)
else
Expand All @@ -76,7 +64,7 @@ def pluck(*cols)
columns_hash.key?(cn) ? arel_table[cn] : cn
}

conn.select_raw(relation) do |result,_|
conn.select_raw(relation, nil, relation.arel.bind_values + bind_values) do |result,_|
result.type_map = SqlBuilder.pg_type_map
result.nfields == 1 ? result.column_values(0) : result.values
end
Expand Down
2 changes: 1 addition & 1 deletion spec/services/random_topic_selector_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
end

it 'can correctly backfill' do
category = Fabricate(:category)
category = Fabricate(:category, sort_order: 'op_likes')
t1 = Fabricate(:topic, category_id: category.id)
_t2 = Fabricate(:topic, category_id: category.id, visible: false)
_t3 = Fabricate(:topic, category_id: category.id, deleted_at: 1.minute.ago)
Expand Down

1 comment on commit d28d8a1

@arpitjalan
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Please sign in to comment.