fix story pagination and caching for logged-out users

use a file store so each unicorn process can share the same set of
files (using redis would probably be cleaner)

put page number into how hash when creating the cache key
This commit is contained in:
joshua stein 2014-02-16 09:55:32 -06:00
parent a16e99c686
commit 0d6f4ed60c
2 changed files with 5 additions and 5 deletions

View file

@ -122,9 +122,9 @@ class HomeController < ApplicationController
private
def find_stories(how = {})
@page = 1
@page = how[:page] = 1
if params[:page].to_i > 0
@page = params[:page].to_i
@page = how[:page] = params[:page].to_i
end
# guest views have caching, but don't bother for logged-in users or dev or
@ -193,7 +193,7 @@ private
)
end
if how[:recent] && @page == 1
if how[:recent] && how[:page] == 1
# try to help recently-submitted stories that didn't gain traction
story_ids = []
@ -228,7 +228,7 @@ private
).limit(
STORIES_PER_PAGE + 1
).offset(
(@page - 1) * STORIES_PER_PAGE
(how[:page] - 1) * STORIES_PER_PAGE
).order(
(how[:newest] || how[:recent]) ? "stories.created_at DESC" : "hotness"
).to_a

View file

@ -30,7 +30,7 @@ module Lobsters
# Raise an exception when using mass assignment with unpermitted attributes
config.action_controller.action_on_unpermitted_parameters = :raise
config.cache_store = :memory_store
config.cache_store = :file_store, "#{config.root}/tmp/cache/"
end
end