From 0d6f4ed60c55fcc91487df684cb0f2359e63e610 Mon Sep 17 00:00:00 2001 From: joshua stein Date: Sun, 16 Feb 2014 09:55:32 -0600 Subject: [PATCH] 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 --- app/controllers/home_controller.rb | 8 ++++---- config/application.rb | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 5d5ced7..87730c3 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -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 diff --git a/config/application.rb b/config/application.rb index 99c9cc2..39caec1 100644 --- a/config/application.rb +++ b/config/application.rb @@ -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