Skip to content

Commit

Permalink
Fix /secretz
Browse files Browse the repository at this point in the history
  • Loading branch information
wioux committed Apr 18, 2015
1 parent 6f7ca41 commit 2239db5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
11 changes: 6 additions & 5 deletions app/models/listen.rb
Expand Up @@ -82,14 +82,15 @@ def self.last_30_days_chart
end

def self.most_active_ips(limit=25)
Listen.count(:all, :group => :ip, :conditions => ['created_at > ?',30.days.ago], :order => 'count_all DESC', :limit => limit)
Listen.where('created_at > ?', 30.days.ago).
order('count_all DESC').
group(:ip).limit(limit).count
end

def self.most_active_tracks(limit=25)
Listen.count(:all,
:from => "listens IGNORE INDEX(index_listens_on_asset_id)",
:group => :asset,
:conditions => ['created_at > ?',30.days.ago], :order => 'count_all DESC', :limit => limit)
Listen.from('listens IGNORE INDEX(index_listens_on_asset_id)').
where('created_at > ?', 30.days.ago).order('count_all DESC').
group(:asset).limit(limit).count
end

def self.find_user_by_ip(ip)
Expand Down
10 changes: 10 additions & 0 deletions db/migrate/20150417235646_add_default_to_users_bandwidth_used.rb
@@ -0,0 +1,10 @@
class AddDefaultToUsersBandwidthUsed < ActiveRecord::Migration
def up
change_column :users, :bandwidth_used, :integer, :default => 0
User.where('bandwidth_used IS NULL').update_all(:bandwidth_used => 0)
end

def down
change_column :users, :bandwidth_used, :integer
end
end
8 changes: 4 additions & 4 deletions db/schema.rb
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20150305213613) do
ActiveRecord::Schema.define(version: 20150417235646) do

create_table "assets", force: :cascade do |t|
t.string "mp3_content_type"
Expand Down Expand Up @@ -59,7 +59,7 @@
t.integer "commenter_id"
t.integer "user_id"
t.string "remote_ip"
t.string "user_agent"
t.string "user_agent", limit: 511
t.string "referrer"
t.boolean "is_spam", default: false
t.boolean "private", default: false
Expand Down Expand Up @@ -183,7 +183,7 @@
t.integer "track_owner_id"
t.string "source"
t.string "ip"
t.string "user_agent"
t.string "user_agent", limit: 511
end

add_index "listens", ["asset_id"], name: "index_listens_on_asset_id"
Expand Down Expand Up @@ -395,7 +395,7 @@
t.string "persistence_token"
t.string "perishable_token"
t.datetime "last_request_at"
t.integer "bandwidth_used"
t.integer "bandwidth_used", default: 0
t.boolean "greenfield_enabled", default: false
end

Expand Down

0 comments on commit 2239db5

Please sign in to comment.