Skip to content

Commit

Permalink
fix admin
Browse files Browse the repository at this point in the history
  • Loading branch information
hooopo committed Oct 24, 2019
1 parent 9faa265 commit 90f120a
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 8 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -221,3 +221,4 @@ gem 'colored2', require: false
gem 'maxminddb'
gem 'marginalia'
gem "default_value_for"
gem 'searchkick'
13 changes: 13 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,14 @@ GEM
in_threads (~> 1.3)
progress (~> 3.0, >= 3.0.1)
docile (1.3.1)
elasticsearch (7.3.0)
elasticsearch-api (= 7.3.0)
elasticsearch-transport (= 7.3.0)
elasticsearch-api (7.3.0)
multi_json
elasticsearch-transport (7.3.0)
faraday
multi_json
email_reply_trimmer (0.1.12)
ember-data-source (3.0.2)
ember-source (>= 2, < 3.0)
Expand Down Expand Up @@ -376,6 +384,10 @@ GEM
sprockets (> 3.0)
sprockets-rails
tilt
searchkick (4.1.0)
activemodel (>= 5)
elasticsearch (>= 6)
hashie
seed-fu (2.3.9)
activerecord (>= 3.1)
activesupport (>= 3.1)
Expand Down Expand Up @@ -532,6 +544,7 @@ DEPENDENCIES
sanitize
sassc
sassc-rails
searchkick
seed-fu
shoulda-matchers (~> 3.1, >= 3.1.3)
sidekiq
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/admin/screened_ip_addresses_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ def index
filter = IPAddr.handle_wildcards(filter)

screened_ip_addresses = ScreenedIpAddress
screened_ip_addresses = screened_ip_addresses.where("cidr :filter >>= ip_address", filter: filter) if filter.present?
screened_ip_addresses = screened_ip_addresses.limit(200).order('match_count desc')
screened_ip_addresses = screened_ip_addresses.where("ip_address LIKE ?", filter: filter) if filter.present?
screened_ip_addresses = screened_ip_addresses.limit(200)

begin
screened_ip_addresses = screened_ip_addresses.to_a
Expand Down
6 changes: 3 additions & 3 deletions app/models/topic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ def self.count_exceeds_minimum?
end

def best_post
posts.where(post_type: Post.types[:regular], user_deleted: false).order('score desc nulls last').limit(1).first
posts.where(post_type: Post.types[:regular], user_deleted: false).order('score desc').limit(1).first
end

def has_flags?
Expand Down Expand Up @@ -1225,7 +1225,7 @@ def message_archived?(user)
TIME_TO_FIRST_RESPONSE_SQL ||= <<-SQL
SELECT AVG(t.hours)::float AS "hours", t.created_at AS "date"
FROM (
SELECT t.id, t.created_at::date AS created_at, EXTRACT(EPOCH FROM MIN(p.created_at) - t.created_at)::float / 3600.0 AS "hours"
SELECT t.id, t.created_at::date AS created_at, TIMESTAMPDIFF(second, MIN(p.created_at), t.created_at) / 3600.0 AS "hours"
FROM topics t
LEFT JOIN posts p ON p.topic_id = t.id
/*where*/
Expand All @@ -1238,7 +1238,7 @@ def message_archived?(user)
TIME_TO_FIRST_RESPONSE_TOTAL_SQL ||= <<-SQL
SELECT AVG(t.hours)::float AS "hours"
FROM (
SELECT t.id, EXTRACT(EPOCH FROM MIN(p.created_at) - t.created_at)::float / 3600.0 AS "hours"
SELECT t.id, TIMESTAMPDIFF(second, MIN(p.created_at), t.created_at) / 3600.0 AS "hours"
FROM topics t
LEFT JOIN posts p ON p.topic_id = t.id
/*where*/
Expand Down
6 changes: 3 additions & 3 deletions lib/admin_user_index_query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ def initialize(params = {}, klass = User, trust_levels = TrustLevel.levels)

SORTABLE_MAPPING = {
'created' => 'created_at',
'last_emailed' => "COALESCE(last_emailed_at, to_date('1970-01-01', 'YYYY-MM-DD'))",
'seen' => "COALESCE(last_seen_at, to_date('1970-01-01', 'YYYY-MM-DD'))",
'last_emailed' => "COALESCE(last_emailed_at, DATE_FORMAT('1970-01-01', 'YYYY-MM-DD'))",
'seen' => "COALESCE(last_seen_at, DATE_FORMAT('1970-01-01', 'YYYY-MM-DD'))",
'username' => 'username',
'email' => 'email',
'trust_level' => 'trust_level',
Expand Down Expand Up @@ -54,7 +54,7 @@ def initialize_query_with_order(klass)

if !custom_order.present?
if params[:query] == "active"
order << "COALESCE(users.last_seen_at, to_date('1970-01-01', 'YYYY-MM-DD')) DESC"
order << "COALESCE(users.last_seen_at, DATE_FORMAT('1970-01-01', 'YYYY-MM-DD')) DESC"
else
order << "users.created_at DESC"
end
Expand Down

0 comments on commit 90f120a

Please sign in to comment.