Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

More sql/active record love/tuning for home page.

  • Loading branch information...
commit 4904b155648048f20e43d70516a44a05cc7af52d 1 parent bff5fcc
@sudara authored
View
22 .gitignore
@@ -2,43 +2,23 @@
.bundle
public/system/*
db/*.sqlite3
+*.sqlite3
log/*.log
tmp/**/*
vendor/bundle/**
.DS_Store
-.sass-cache
/.DS_Store
update
-.rvmrc
config/deploy.rb
config/deploy/*
config/alonetone.yml
config/config.yml
config/database.yml
-config/amazon_s3.yml
config/defensio.yml
-config/basecamp.yml
config/newrelic.yml
config/memcached.yml
config/deploy/*
*.sql
-public/stylesheets/alonetone-v2.css
-public/stylesheets/alonetone.css
-public/javascripts/allonetone.js
-public/javascripts/alonetone-v2.jss
-public/stylesheets/flash.css
-public/stylesheets/ie6.css
-public/stylesheets/nav.css
-public/stylesheets/player.css
-public/stylesheets/playlists.css
-public/stylesheets/reset.css
-public/stylesheets/share.css
-public/stylesheets/tabs.css
-public/stylesheets/tracks.css
-public/stylesheets/typography.css
-public/stylesheets/variables.css
-public/stylesheets/layout.css
-public/stylesheets/forums.css
public/mp3
public/pics
public/source_files
View
28 app/controllers/assets_controller.rb
@@ -80,29 +80,21 @@ def hot_track
def latest
respond_to do |wants|
wants.html do
- @limit = (params[:latest] && params[:latest].to_i < 50) ? params[:latest] : 5
@page_title = @description = "Latest #{@limit} uploaded mp3s" if params[:latest]
- @assets = Asset.latest(@limit).includes(:user => :pic)
- @favorites = Track.favorites.limit(5)
- @popular = Asset.limit(@limit).order('hotness DESC').includes(:user => :pic)
- @comments = if admin?
- Comment.on_track.include_private.limit(5).includes(:commentable => :user)
- else
- Comment.on_track.public.by_member.limit(5).includes(:commentable => :user)
- end
- @playlists = Playlist.public.latest(12).includes(:pic)
@tab = 'home'
- @welcome = true unless logged_in?
- @feature = Feature.published.first
- if logged_in? and current_user.has_followees?
- @followee_tracks = current_user.new_tracks_from_followees(5)
- end
+
+ @assets = Asset.latest.includes(:user => :pic).limit(5)
+ @favorites = Track.favorites_for_home
+ @popular = Asset.limit(5).order('hotness DESC').includes(:user => :pic)
+ @comments = admin? ? Comment.last_5_private : Comment.last_5_public
+ @playlists = Playlist.for_home
+ @followee_tracks = current_user.new_tracks_from_followees(5) if user_has_tracks_from_followees?
end
wants.rss do
@assets = Asset.latest(50)
end
wants.json do
- @assets = Asset.limit(5000).includes(:user)
+ @assets = Asset.limit(1000).includes(:user)
render :json => @assets.to_json(:only => [:name, :title, :id], :methods => [:name], :include =>{:user => {:only => :name, :method => :name}})
end
end
@@ -260,6 +252,10 @@ def not_found
redirect_to user_tracks_path(@user)
end
+ def user_has_tracks_from_followees?
+ logged_in? and current_user.has_followees?
+ end
+
def find_referer
@referer = case params[:referer]
when 'itunes' then 'itunes'
View
2  app/models/comment.rb
@@ -6,6 +6,8 @@ class Comment < ActiveRecord::Base
scope :by_member, recent.where('commenter_id IS NOT NULL')
scope :include_private, recent.where(:spam => false)
scope :on_track, where(:commentable_type => 'Asset')
+ scope :last_5_private, on_track.include_private.limit(5).includes(:commenter => :pic, :commentable => {:user => :pic})
+ scope :last_5_public, on_track.public.by_member.limit(5).includes(:commenter => :pic, :commentable => {:user => :pic})
belongs_to :commentable, :polymorphic => true, :touch => true
View
2  app/models/playlist.rb
@@ -8,6 +8,8 @@ class Playlist < ActiveRecord::Base
scope :favorites, where(:is_favorite => true)
scope :public, where(:private => false).where(:is_favorite => false).where("tracks_count > 1")
scope :include_private, where(:is_favorite => false)
+ scope :recent, order('playlists.created_at DESC')
+ scope :for_home, recent.public.limit(12).includes(:user, :pic)
belongs_to :user, :counter_cache => true
has_one :pic, :as => :picable, :dependent => :destroy
View
2  app/models/track.rb
@@ -19,6 +19,8 @@ class Track < ActiveRecord::Base
scope :recent, order('tracks.created_at DESC')
scope :favorites, where(:is_favorite => true).recent
+ scope :favorites_for_home, favorites.limit(5).includes({:user => :pic}, {:asset => {:user => :pic}})
+
acts_as_list :scope => :playlist_id, :order => :position
validates_presence_of :asset_id, :playlist_id
View
5 app/models/user.rb
@@ -7,7 +7,10 @@ class User < ActiveRecord::Base
c.login_field = :login
c.disable_perishable_token_maintenance = true # we will handle tokens
end
-
+
+ # beta test this to see if appropriate
+ default_scope includes(:pic)
+
scope :recent, order('users.id DESC')
scope :recently_seen, order('last_login_at DESC')
scope :musicians, where(['assets_count > ?',0]).order('assets_count DESC')
View
9 app/views/shared/_favorite.html.erb
@@ -1,9 +1,8 @@
-<% asset = favorite.asset %>
-<%= content_tag :div, :id => ("asset_#{asset.unique_id}"), :class => 'asset ' + cycle('odd', 'even') do %>
- <%= render :layout => 'assets/asset_layout', :locals => {:asset => asset, :referer => (@referer) } do %>
- <%= link_to asset.user.name, user_home_path(asset.user), :class => 'artist' %>
+<%= content_tag :div, :id => ("asset_#{favorite.asset.unique_id}"), :class => 'asset ' + cycle('odd', 'even') do %>
+ <%= render :layout => 'assets/asset_layout', :locals => {:asset => favorite.asset, :referer => (@referer) } do %>
+ <%= link_to favorite.asset.user.name, user_home_path(favorite.asset.user), :class => 'artist' %>
<%= link_to "(fav'd by #{favorite.user.name})", user_home_path(favorite.user), :class => 'artist' %>
<% end %>
<% end %>
-<%= render :partial => 'assets/asset_tabs', :locals => {:asset => asset} unless @single_track %>
+<%= render :partial => 'assets/asset_tabs', :locals => {:asset => favorite.asset} unless @single_track %>
View
5 db/migrate/20130213150415_add_indexes_to_asset.rb
@@ -0,0 +1,5 @@
+class AddIndexesToAsset < ActiveRecord::Migration
+ def change
+ add_index "assets", "hotness"
+ end
+end
View
3  db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20120930000305) do
+ActiveRecord::Schema.define(:version => 20130213150415) do
create_table "assets", :force => true do |t|
t.string "mp3_content_type"
@@ -44,6 +44,7 @@
t.datetime "updated_at"
end
+ add_index "assets", ["hotness"], :name => "index_assets_on_hotness"
add_index "assets", ["permalink"], :name => "index_assets_on_permalink"
add_index "assets", ["user_id", "listens_per_week"], :name => "index_assets_on_user_id_and_listens_per_day"
add_index "assets", ["user_id"], :name => "index_assets_on_user_id"
View
BIN  public/flash/alonetone_player.swf
Binary file not shown
View
BIN  public/flash/mediaplayer.swf
Binary file not shown
View
BIN  public/flash/soundmanager2.swf
Binary file not shown
Please sign in to comment.
Something went wrong with that request. Please try again.