Permalink
Browse files

revert to previous /newest behavior, use new stuff for /recent

/recent is not yet linked to from anywhere
  • Loading branch information...
jcs committed Jan 25, 2014
1 parent 8dbc0e4 commit df75c8f78782c68a892ce63075098a60c2a6f70f
Showing with 21 additions and 9 deletions.
  1. +19 −9 app/controllers/home_controller.rb
  2. +2 −0 config/routes.rb
@@ -1,11 +1,11 @@
class HomeController < ApplicationController
STORIES_PER_PAGE = 25
# how many points a story has to be bumped off the newest page
# how many points a story has to have to probably get on the front page
HOT_STORY_POINTS = 5
# how many days old a story can be to get on the bottom half of /newest
NEWEST_DAYS_OLD = 3
# how many days old a story can be to get on the bottom half of /recent
RECENT_DAYS_OLD = 3
# for rss feeds, load the user's tag filters if a token is passed
before_filter :find_user_from_rss_token, :only => [ :index, :newest ]
@@ -71,6 +71,16 @@ def newest_by_user
render :action => "index"
end
def recent
@stories = find_stories({ :recent => true })
@heading = @title = "Recent Stories"
@cur_url = "/recent"
@recent = true
render :action => "index"
end
def tagged
@tag = Tag.where(:tag => params[:tag]).first!
@@ -123,8 +133,8 @@ def find_stories(how = {})
stories, @show_more = _find_stories(how)
else
stories, @show_more = Rails.cache.fetch("stories " <<
"tag:#{how[:tag].try(:tag)} new:#{how[:newest]} page:#{@page.to_i} " <<
"by:#{how[:by_user].try(:id)}", :expires_in => 45) do
how.sort.map{|k,v| "#{k}=#{v.to_param}" }.join(" "),
:expires_in => 45) do
_find_stories(how)
end
end
@@ -163,7 +173,7 @@ def _find_stories(how)
stories = stories.where(
Story.arel_table[:id].in(
Tagging.arel_table.where(
Tagging.arel_table[:tag_id].eq(tag.id)
Tagging.arel_table[:tag_id].eq(how[:tag].id)
).project(
Tagging.arel_table[:story_id]
)
@@ -183,13 +193,13 @@ def _find_stories(how)
)
end
if how[:newest] && @page == 1
if how[:recent] && @page == 1
# try to help recently-submitted stories that didn't gain traction
# grab the list of stories from the past n days, shifting out popular
# stories that did gain traction
story_ids = stories.select(:id, :upvotes, :downvotes).
where(Story.arel_table[:created_at].gt(NEWEST_DAYS_OLD.days.ago)).
where(Story.arel_table[:created_at].gt(RECENT_DAYS_OLD.days.ago)).
order("stories.created_at DESC").
reject{|s| s.score > HOT_STORY_POINTS }
@@ -215,7 +225,7 @@ def _find_stories(how)
).offset(
(@page - 1) * STORIES_PER_PAGE
).order(
how[:newest] ? "stories.created_at DESC" : "hotness"
(how[:newest] || how[:recent]) ? "stories.created_at DESC" : "hotness"
).to_a
show_more = false
View
@@ -12,6 +12,8 @@
get "/newest/page/:page" => "home#newest"
get "/newest/:user" => "home#newest_by_user"
get "/newest/:user/page/:page" => "home#newest_by_user"
get "/recent" => "home#recent"
get "/recent/page/:page" => "home#recent"
get "/threads" => "comments#threads"
get "/threads/:user" => "comments#threads"

0 comments on commit df75c8f

Please sign in to comment.