Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion pagination issue with memcached
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Pat Allan  
View profile  
 More options Sep 21 2010, 9:23 am
From: Pat Allan <p...@freelancing-gods.com>
Date: Tue, 21 Sep 2010 23:23:33 +1000
Local: Tues, Sep 21 2010 9:23 am
Subject: Re: [ts] Re: pagination issue with memcached
Hmm, this is odd. I think memcached calls freeze on objects it caches... but that shouldn't convert the search to an array (although it does freeze the underlying array).

Maybe Jim's suggestion is the best approach as a quick fix? Cache both the results and the total? Although it won't fix pagination - because WillPaginate expects a bit more information than that...

If you want to debug further, I'd start by seeing what memcached does when you cache an object.

--
Pat

On 21/09/2010, at 12:06 PM, Jim Ruther Nill wrote:

> I think there's no way around this. memcache the object and memcache the total count.

> On Tue, Sep 21, 2010 at 8:00 AM, badnaam <asitkmis...@gmail.com> wrote:
> Update

> OK, the issue is related to the face that the collection needs to be
> of type Will_Paginte::Collection. TS Search by default returns the
> results of this type, that why it works when the block is executed,
> but memcached returns just an array and hence it doesn't work.

> I tried converting the memcached Array to a will_paginate:collection
> type like...

> if results.class == ThinkingSphinx::Search
>            return results
>        else
>            pag_results = WillPaginate::Collection.create(page,
> per_page) do |pager|
>                pager.replace(results)
>                unless pager.total_entries
>                    # the pager didn't manage to guess the total
> count, do it manually
>                    pager.total_entries = results.count ##this is bad
>                end

>            end
>            return pag_results
>        end

> But the problem is results does not contain the entire search count,
> only the first paginated lot and without doing the search all again, I
> can't calculate the exact count, which would defeat the purpose of
> memcaching it, since everytime there is a cache hit I would have to
> run the search again just to find the total count.

> Bump!

> On Sep 19, 1:48 pm, badnaam <asitkmis...@gmail.com> wrote:
> > I memcached (with Dalli client) some of my search results like..

> > def self.city_search  city, per_page, page, order
> >         Rails.cache.fetch("#{city}_#{page}_#{order}") do
> >             Post.search(:include => [:poster, :category],:geo =>
> > location_lat_lng_radian(city),
> >               :with => {"@geodist" => 0.0..(Constants::PROXIMITY *
> > Constants::METERS_PER_MILE), :status => Post::STATUS['approved']},
> >               :latitude_attr => :lat, :longitude_attr
> > => :lng, :per_page => per_page, :page => page, :order =>
> > (ModelHelpers.determine_order_search order))
> >         end
> >     end

> > ##In controller
> > @search_results  = Search.city_search params[:city], params[:per_page]
> > || Constants::LISTINGS_PER_PAGE, params[:page] || 1, params[:order] ||
> > 'distance'

> > The result is presented in the view with pagination like..

> > <%= page_entries_info @search_results, :entry_name => "Search Result"
> > %>
> >   <%= will_paginate @search_results, :class => 'pagination' %>

> > The first hit i.e. when the block is exececuted and the return type of
> > the collection is "ThinkingSphinx::Search" this all works fine. The
> > 2nd time when there is a cache hit and the collection returned from
> > the city_search method is of type "Array" I get  the following error.

> > If I convert the results of the block to an array so that the view
> > always get an Array (regardless of cached or non cached hit), the
> > first hit i.e. non-cached hit, get the same exact error.

> > Will paginate's page_entires_info expect a collection..so why am I
> > seeing this? Not sure if this is a will paginate or thinkingsphinx
> > issue.

> > undefined method `total_pages' for #<Array:0xa068c40>
> > /usr/local/lib/ruby/gems/1.8/gems/will_paginate-2.3.14/lib/
> > will_paginate/view_helpers.rb:171:in `page_entries_info'
> > /home/username/Apps/myapp/app/views/searches/_search_results.html.erb:
> > 7:in
> > `_run_erb_app47views47searches47_search_results46html46erb_locals_object_pa ginate_search_results'
> > /home/username/Apps/myapp/app/views/searches/index.html.erb:4:in
> > `_run_erb_app47views47searches47index46html46erb'
> > /home/username/Apps/myapp/app/controllers/searches_controller.rb:28:in
> > `index'

> --
> You received this message because you are subscribed to the Google Groups "Thinking Sphinx" group.
> To post to this group, send email to thinking-sphinx@googlegroups.com.
> To unsubscribe from this group, send email to thinking-sphinx+unsubscribe@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/thinking-sphinx?hl=en.

> --
> -------------------------------------------------------------
> visit my blog at http://jimlabs.heroku.com

> --
> You received this message because you are subscribed to the Google Groups "Thinking Sphinx" group.
> To post to this group, send email to thinking-sphinx@googlegroups.com.
> To unsubscribe from this group, send email to thinking-sphinx+unsubscribe@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/thinking-sphinx?hl=en.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.