Posts#index page caching breaks pagination #257

Closed
mrGrazy opened this Issue Jul 23, 2012 · 10 comments

Projects

None yet

5 participants

@mrGrazy

Even though we're using the latest 2-0-stable (including #222), we still have issues with pagination in posts index.

This is what seems to be happening:

caches_page :index, :unless => proc {|c| c.refinery_user_signed_in? || c.flash.any? || params[:page].present? }

The posts controller only caches the page if there is no page param, however the unless filter is not evaluated if there is a cache hit.
The first time you go to /blog it caches the page, and from then on /blog?page=anything hits the cached page for /blog.

We can disable the page cache by doing this in a decorator:

Refinery::Blog::PostsController.class_eval do
  before_filter :prevent_caching, :only => [:index]

  protected

  def prevent_caching
    params[:page] ||= 1
  end
end

Which is less then ideal. I have my doubts that page caching should be used for index at all, as it doesn't handle parameters.

@parndt
Refinery member
@robyurkowski

@mrGrazy Do you have time to contribute a patch for this?

@mrGrazy

Sorry about the delay, yes I do. I'll work on it tomorrow morning.

@jondkinney

How can I take advantage of this being removed when using the 2.0 stable versions of things? It doesn't seem to be removed from the 2.0.4 version of refinerycms-blog and it's breaking pagination in my production environment. I could manually bundle edit the gems on production, but that's brittle. Do I have to fork this and reference my fork with the pull request applied? Should I reference a specific commit version of the 2.0.x branch? Thanks.

@jondkinney

Well, I'm going to give this a shot:

gem 'refinerycms-blog', github: 'refinery/refinerycms-blog', branch: '2-0-stable'

I'm not sure if that's the best version to use or if it's way ahead/behind the 2.0.4 gem version I was using (which didn't have a tag incidentally) but hopefully it works.

@markgarrigan

So do I need to add the decorator or not? I'm using 2-0-stable. You can see here... http://news.wspackaging.com/ that pagination doesn't work.

I also have this in the routes file...

root :to => 'refinery/blog/posts#index'

This is also a problem...

http://news.wspackaging.com appears to be cached but
http://news.wspackaging.com/blog is not cached.

Either way pagination does not work.

@parndt
Refinery member

@markgarrigan looks like @mrGrazy contributed a patch which removed caching on the posts controller. Can you try this in your Gemfile:

gem 'refinerycms-blog', :github => 'refinery/refinerycms-blog', :branch => '2-0-stable'

If that works, I'll push 2.0.5

@markgarrigan

I'll try that now.

@markgarrigan

That appears to have worked.

gem 'refinerycms-blog', :github => 'refinery/refinerycms-blog', :branch => '2-0-stable'
@parndt
Refinery member

Alright, thanks, I've pushed version 2.0.5 to rubygems.org so you should be able to use a normal dependency now.

@parndt parndt closed this Jul 26, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment