I had a senior colleague lend a hand, and we went a different route. I took the hour interval and limit out of the sql query, and the looped through the results in ruby to return > 12 results, each time increasing the interval +17 hours, until we get + 12. Once we hit that threshold we break. Thanks for the help!
#DEALS TAB BEGIN
def self.deals
#calculate the raw percentage, minus that from 100 to show percentage off
options = {:select => "100 - round((current_price / item.estimated_price)*100) as percent, item.cached_thumbnail_url, item.item_id, it.name, ci.current_price, ci.close_date, ci.catalog_item_id",
:from => "catalog_item AS ci",
:joins => "JOIN item on item.item_id = ci.item_id
JOIN item_translations it ON (it.item_id = item.item_id)",
:order => "(item.estimated_price - current_price) DESC",
:conditions => "(100 - round((current_price / item.estimated_price)*100)) > 49 AND
item.estimated_price > 0 AND
ci.current_price > 0 AND
ci.close_date > DATE_ADD(NOW(), interval #{-1*Time.now.utc_offset} second) AND
item.active = 1 AND
ci.active = 1 AND
(current_price / estimated_price) < 1 "}
#loop adding 17 hours each pass until < 12 results show
catalog_items = CatalogItem.all(options)
_deals = []
if catalog_items.present?
last_close_date = CatalogItem.first(:conditions => options[:conditions], :from => options[:from], :joins => options[:joins], :order => "ci.close_date DESC", :select => options[:select]).close_date
start_time = Time.now
interval = 17.hours
end_time = start_time + interval
min_needed_for_view = 12
until _deals.size >= min_needed_for_view or last_close_date < start_time
catalog_items.each do |ci|
if ci.close_date < end_time && ci.close_date > start_time
_deals.push(ci)
break if _deals.size >= min_needed_for_view
end
end
start_time = end_time
end_time += interval
end
end
_deals
end