Collection rendering and use of read_multi

77 views
Skip to first unread message

m

unread,
Jan 31, 2013, 10:57:08 PM1/31/13
to cells-an...@googlegroups.com
I am thinking maybe we can add similar functionality like Rails' partial collection rendering. It not only makes code cleaner, but also leverage the cache store's read_multi method. This post says that there is significant saving in cache fetching time.

I think the first step would be to think of the syntax for collection rendering. Maybe 'render_cells'?

Currently Rails partial collection can only pass one input parameter. I think it is possible to do more if we use blocks.

render_cells :book, :page, @pages do |page|
  [page, dynamic?(page)]
end

This would pass the page and some computed value based on it to the cell.

What do you guys think?

Nick Sutterer

unread,
Feb 1, 2013, 4:10:02 AM2/1/13
to cells-an...@googlegroups.com
Hi Markus, thanks for that suggestion. How would a
collection-rendering make use of the read_multi caching? How is that
used at all? Ok, maybe I should read the post, first ;-) But remember
that cells has its own caching!

I was playing with something like

render_cell :comments, :show, :collection => @pages

but you are right, what if you need more than one arg to pass into the
cell? Then you'd need an additional list like

render_cell :comments, :show, :collection => @pages, current_user

Or you'd need a block, as you propose.


render_cell :comments, :show, :collection => @pages do |page|
page, current_user
end

which would interfere with the original block for render_cell. That
leads us to #render_cells, which is 100% your idea :-)

I need to check how we can use read_multi in the cell caching, then we
can think about adding this change. Thanks again!

Nick
> --
> Sie haben diese Nachricht erhalten, weil Sie der Google Groups-Gruppe Cells
> and Apotomo beigetreten sind.
> Um Ihr Abonnement für diese Gruppe zu beenden und keine E-Mails mehr von
> dieser Gruppe zu erhalten, senden Sie eine Email an
> cells-and-apot...@googlegroups.com.
> Weitere Optionen: https://groups.google.com/groups/opt_out
>
>

m

unread,
Feb 26, 2013, 9:50:58 PM2/26/13
to cells-an...@googlegroups.com
Hi Nick

Here is the API document for read_multi. So basically if I uses Memcached as caching store, read_multi can then fetch multiple caches from the store in one Memcached command.

Of course this can only happen when we can easily know what things to fetch, which is the case when we are using:
<%= render :partial => "product", :collection => @products %>

So it would be great if we can do the same thing for Cells.

Nick Sutterer於 2013年2月1日星期五UTC+8下午5時10分02秒寫道:

m

unread,
Oct 15, 2013, 6:10:46 AM10/15/13
to cells-an...@googlegroups.com
Hi Nick

I have hacked a gem which will render a collection of items in one go. I am wondering if you can take a look.

https://github.com/GoodLife/cells-collection

It does render okay, but I don't know if some of the logic I have implemented are at the right abstraction level. So I am wondering if you can take a look.

By the way the performance boost I have seen are not that great. Sometimes the additional Ruby overhead can even outweigh the saving.

Cheers

Nick Sutterer於 2013年2月1日星期五UTC+8下午5時10分02秒寫道:

Nick Sutterer

unread,
Oct 15, 2013, 6:35:21 AM10/15/13
to cells-an...@googlegroups.com
Cool! It looks as if there is lot of redudancy with the original Cells code. Maybe we can make the parts you need to override a bit easier to extend in Cells itself?


--
Sie erhalten diese Nachricht, weil Sie Mitglied der Google Groups-Gruppe "Cells and Apotomo" sind.

m

unread,
Oct 15, 2013, 10:39:48 PM10/15/13
to cells-an...@googlegroups.com
I am thinking if you can have compute_key https://github.com/GoodLife/cells-collection/blob/master/lib/cells-collection/cell/caching.rb#L59 in cells. I need get the keys by calling the state_cache_key but it is protected, so I wrote this public wrapper.

As for other things, I understand that a cell.cache? can depend on both the global setting and cell instance state. I am wondering if I can know if that cell is cachable or not at the global setting level, so my
render_cell_collection_for method can call super() (the non caching version). Do you think it is possible? Currently I need to check each cell.cache? separately.

Lastly, I am a bit confused about https://github.com/GoodLife/cells-collection/blob/master/lib/cells-collection/cell/caching.rb#L27 . In that line I need to remove an argument in order to compute key. This led me into thinking maybe I am at the wrong abstraction level.

Thanks for the help!

Nick Sutterer於 2013年10月15日星期二UTC+8下午6時35分21秒寫道:

Nick Sutterer

unread,
Oct 15, 2013, 10:51:32 PM10/15/13
to cells-an...@googlegroups.com
You'd just check the global caching flag (or the flag of the first cell instance) for a collection.

How do you compute the cache key for your collection, what items do you use for the key?

I believe when we move some of the parts to separate methods you can re-use all of it.

m

unread,
Oct 16, 2013, 5:37:33 AM10/16/13
to cells-an...@googlegroups.com
Nick Sutterer於 2013年10月16日星期三UTC+8上午10時51分32秒寫道:
You'd just check the global caching flag (or the flag of the first cell instance) for a collection.

Do you mean cache_configured? I just noticed it.
 
How do you compute the cache key for your collection, what items do you use for the key?

I loop through all items, and get the keys from them one by one (like how one key is obtained from normal cell rendering).
 
I believe when we move some of the parts to separate methods you can re-use all of it.

Cool! That would be great!
Reply all
Reply to author
Forward
0 new messages