From 435fe52e4a6f85e244cbc73875d04b7e42b4e2b4 Mon Sep 17 00:00:00 2001 From: Lee Lawlor Date: Wed, 19 Nov 2014 09:18:15 -0500 Subject: [PATCH] don't use turbolinks on public channels list --- app/controllers/application_controller.rb | 13 +++++++++---- app/models/feed_factory.rb | 23 ++++++++++++++++++++--- app/views/channels/_list.html.erb | 2 +- 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 9dbd910..23344c8 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -296,12 +296,17 @@ class ApplicationController < ActionController::Base # allow more past data if necessary get_old_data = (params[:results].present? || params[:start].present? || params[:days].present?) ? true : false - # set default start date + # set default start and end dates start_date = (get_old_data) ? Time.parse('2010-01-01') : (Time.now - 1.day) end_date = Time.now - start_date = (Time.now - params[:days].to_i.days) if params[:days] - start_date = ActiveSupport::TimeZone[Time.zone.name].parse(params[:start]) if params[:start] - end_date = ActiveSupport::TimeZone[Time.zone.name].parse(params[:end]) if params[:end] + + # set new start and end dates if necessary + start_date = (Time.now - params[:days].to_i.days) if params[:days].present? + start_date = (Time.now - params[:minutes].to_i.minutes) if params[:minutes].present? + start_date = ActiveSupport::TimeZone[Time.zone.name].parse(params[:start]) if params[:start].present? + end_date = ActiveSupport::TimeZone[Time.zone.name].parse(params[:end]) if params[:end].present? + + # set the date range date_range = (start_date..end_date) # only get a maximum of 30 days worth of data date_range = (end_date - 30.days..end_date) if ((end_date - start_date) > 30.days and !get_old_data) diff --git a/app/models/feed_factory.rb b/app/models/feed_factory.rb index 2cb578e..ee2d7f0 100644 --- a/app/models/feed_factory.rb +++ b/app/models/feed_factory.rb @@ -20,6 +20,15 @@ class FeedFactory < ApplicationController # attributes that can be read attr_reader :feeds, :daily_feeds, :limit, :use_daily_feed, :feed_select_options, :cache_feeds, :channel + # range for entry_ids + def entry_id_range + # set start and end id + start_id = @options[:start_entry_id].present? ? @options[:start_entry_id].to_i : 1 + end_id = @options[:end_entry_id].present? ? @options[:end_entry_id].to_i : @channel.last_entry_id + # return the range + return start_id..end_id + end + # calculate the limit that should be used def calculate_limit limit = 100 @@ -88,10 +97,18 @@ class FeedFactory < ApplicationController # get feeds def get_feeds + # get feeds based on entry ids + if @options[:start_entry_id].present? || @options[:end_entry_id].present? + @feeds = Feed.from("feeds FORCE INDEX (index_feeds_on_channel_id_and_entry_id)") + .where(:channel_id => @channel.id, :entry_id => entry_id_range) # get feed based on conditions - @feeds = Feed.from("feeds FORCE INDEX (index_feeds_on_channel_id_and_created_at)") - .where(:channel_id => @channel.id, :created_at => @date_range) - .select(@feed_select_options) + else + @feeds = Feed.from("feeds FORCE INDEX (index_feeds_on_channel_id_and_created_at)") + .where(:channel_id => @channel.id, :created_at => @date_range) + end + + # apply filters and load the feeds + @feeds = @feeds.select(@feed_select_options) .order('created_at desc') .limit(@limit) .load diff --git a/app/views/channels/_list.html.erb b/app/views/channels/_list.html.erb index f749def..2943498 100644 --- a/app/views/channels/_list.html.erb +++ b/app/views/channels/_list.html.erb @@ -1,6 +1,6 @@ <% @channels.each do |channel| %> -
+