Changeset cb93cb8c2391bcfdff4eefed378aa47f6a8ef266
- Timestamp:
- 07/27/10 09:01:10 (6 weeks ago)
- Author:
- Alban Peignier <alban@…>
- Parents:
- 4c2e420eff672f881710178e0488b6a07aebec4c
- Children:
- c5037a4ce54f151978b2a29e61f78dde36d3cbea
- git-committer:
- Alban Peignier <alban@tryphon.eu> / 2010-07-27T09:01:10Z+0200
- Message:
-
Optimise db usage for PublicController#feed?
- Location:
- app
- Files:
-
Legend:
- Unmodified
- Added
- Removed
-
|
r439b576
|
rcb93cb8
|
|
| 7 | 7 | append_view_path "#{Rails.root}/templates" |
| 8 | 8 | |
| 9 | | before_filter :assigns_show, :assigns_now, :create_user_google_analytics_account |
| | 9 | before_filter :assigns_show, :create_user_google_analytics_account, :except => :feed |
| | 10 | before_filter :assigns_now |
| 10 | 11 | |
| 11 | 12 | rescue_from ActiveRecord::RecordNotFound, :with => :show_home_page_when_not_found |
| … |
… |
|
| 35 | 36 | |
| 36 | 37 | def feed |
| | 38 | current_show [{:episodes => [ :show, { :contents => { :episode => [ :contents, :tags, { :show => :host } ] } }, :tags ]}, :host] |
| 37 | 39 | render :content_type => "application/rss+xml", :layout => false |
| 38 | 40 | end |
| … |
… |
|
| 48 | 50 | |
| 49 | 51 | def direct |
| 50 | | render_template @show, :stream, @show |
| | 52 | render_template current_show, :stream, current_show |
| 51 | 53 | end |
| 52 | 54 | |
| … |
… |
|
| 58 | 60 | |
| 59 | 61 | def vote |
| 60 | | @episode = @show.episodes.find(params[:episode_id]) |
| | 62 | @episode = current_show.episodes.find(params[:episode_id]) |
| 61 | 63 | |
| 62 | 64 | if request.post? and user_session.can_rate_episode?(@episode) |
| … |
… |
|
| 73 | 75 | def tags |
| 74 | 76 | @search = params[:search] |
| 75 | | @episodes = Episode.sort(@show.episodes.find_tagged_with(@search)) |
| | 77 | @episodes = Episode.sort(current_show.episodes.find_tagged_with(@search)) |
| 76 | 78 | |
| 77 | 79 | respond_to do |format| |
| 78 | 80 | format.html { |
| 79 | | render_template @show, :search, @search |
| | 81 | render_template current_show, :search, @search |
| 80 | 82 | } |
| 81 | 83 | format.m3u { |
| … |
… |
|
| 94 | 96 | |
| 95 | 97 | def render_show |
| 96 | | create_visit @show |
| 97 | | render_template @show, :show, @show |
| | 98 | create_visit current_show |
| | 99 | render_template current_show, :show, current_show |
| 98 | 100 | end |
| 99 | 101 | |
| … |
… |
|
| 105 | 107 | end |
| 106 | 108 | |
| 107 | | def assigns_show |
| 108 | | host = Host.find_by_name(request.host) |
| 109 | | unless host.blank? |
| 110 | | @show = host.show |
| 111 | | end |
| 112 | | |
| 113 | | show_slug = "" |
| 114 | | if request.host =~ /^(.*).bonnes-ondes.(fr|local)$/ |
| 115 | | show_slug = $1 |
| 116 | | end |
| 117 | | |
| 118 | | @show = find_show(show_slug) |
| 119 | | end |
| 120 | | |
| 121 | 109 | def assigns_now |
| 122 | 110 | @now = Time.now |
| … |
… |
|
| 124 | 112 | |
| 125 | 113 | def create_user_google_analytics_account |
| 126 | | user_tracker_id = (@show and @show.host and @show.host.google_analytics_tracker_id) |
| | 114 | user_tracker_id = (current_show and current_show.host and current_show.host.google_analytics_tracker_id) |
| 127 | 115 | |
| 128 | 116 | unless user_tracker_id.blank? |
| … |
… |
|
| 131 | 119 | end |
| 132 | 120 | |
| 133 | | def find_show(slug = nil) |
| 134 | | @show ||= Show.find_by_slug(slug) |
| | 121 | def current_show(include = []) |
| | 122 | unless @show |
| | 123 | if host = Host.find_by_name(request.host) |
| | 124 | @show = Show.find(host.show, :include => include) |
| | 125 | else |
| | 126 | if request.host =~ /^(.*).bonnes-ondes.(fr|local)$/ |
| | 127 | @show = Show.find_by_slug($1, :include => include) |
| | 128 | end |
| | 129 | end |
| | 130 | |
| | 131 | raise ActiveRecord::RecordNotFound unless @show |
| | 132 | end |
| | 133 | |
| | 134 | @show |
| 135 | 135 | end |
| | 136 | alias_method :load_show, :current_show |
| | 137 | alias_method :assigns_show, :current_show |
| 136 | 138 | |
| 137 | 139 | def find_episode |
| 138 | | find_show.episodes.find_by_slug(params[:episode_slug]) or raise ActiveRecord::RecordNotFound |
| | 140 | current_show.episodes.find_by_slug(params[:episode_slug]) or raise ActiveRecord::RecordNotFound |
| 139 | 141 | end |
| 140 | 142 | |
-
|
r027b9a4
|
rcb93cb8
|
|
| 3 | 3 | |
| 4 | 4 | def contents_for_feed(show) |
| 5 | | Episode.sort(show.episodes.broadcasted).collect { |e| e.contents.principal }.flatten |
| | 5 | Episode.sort(show.episodes).select(&:broadcasted?).collect do |episode| |
| | 6 | episode.contents.select(&:principal?) |
| | 7 | end.flatten |
| 6 | 8 | end |
| 7 | 9 | |
-
|
r2bbe6cc
|
rcb93cb8
|
|
| 5 | 5 | |
| 6 | 6 | named_scope :principal, :conditions => { :principal => true } |
| | 7 | named_scope :for_feed, lambda { |show| { |
| | 8 | :conditions => [ "shows.id = ? and episodes.broadcasted_at < ?", show.id, Time.now ], |
| | 9 | :include => { :episode => [:tags, :show, :contents] }, |
| | 10 | :order => "episodes.broadcasted_at desc" |
| | 11 | } |
| | 12 | } |
| 7 | 13 | |
| 8 | 14 | liquid_methods :name, :episode, :duration, :has_duration?, :id, :available? |
-
|
r309fce1
|
rcb93cb8
|
|
| 28 | 28 | belongs_to :image |
| 29 | 29 | |
| | 30 | def broadcasted? |
| | 31 | self.broadcasted_at < Time.now |
| | 32 | end |
| | 33 | |
| 30 | 34 | def self.sort(episodes) |
| 31 | 35 | if episodes.all?(&:broadcasted_at) |
-
|
r112123f
|
rcb93cb8
|
|
| 13 | 13 | end |
| 14 | 14 | |
| 15 | | xml.description textilize_in_text(content.episode.description) |
| 16 | | xml.itunes :summary, textilize_in_text(content.episode.description) |
| | 15 | text = textilize_in_text(content.episode.description) |
| | 16 | xml.description text |
| | 17 | xml.itunes :summary, text |
| 17 | 18 | |
| 18 | 19 | xml.itunes :duration, "#{content.duration}:00" if content.has_duration? |