Collection caching: render to strings

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Collection caching: render to strings

GlebM
Hi, I am a contributor to Thredded, a Rails forums engine, and we have an interesting problem.

We currently all cache the posts on a topic page using collection caching.

This requires the entire post to be cached due to the current collection caching interface,
even though only the post content itself is slow to render. That's was not a large problem for us until now.

However, @EllaNancyFay is currently working on a feature for Thredded that requires something that cannot be cached
to be inserted at the end of the post partial, but that's not possible via the current render collection: ..., cache: ... interface.

I'm wondering if a feature that lets us render a collection to Strings would belong in Rails core?

So a method such as render_to_strings(partial:, collection:, cache:),
returning an Array of [ [item, "rendered html"], ... ].

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Collection caching: render to strings

GlebM

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Collection caching: render to strings

Kasper Hansen
Been a while since I’ve last worked with that code but doesn’t a collection cache render return a collection of rendered HTML strings?

I think you might be able to stitch the objects and their rendered HTML together like this:

    @posts.zip(render(partial: ’posts/post’, collection: @posts, cached: true))

Though overall, I don’t think we’re going to change the interface here. Thanks! :)

Den 5. mar. 2017 kl. 10.06 skrev Gleb Mazovetskiy <[hidden email]>:


--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.

--
Kasper

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Collection caching: render to strings

GlebM

No, a collection cache render returns a single string.


On Mon, 20 Mar 2017, 19:15 Kasper Timm Hansen, <[hidden email]> wrote:
Been a while since I’ve last worked with that code but doesn’t a collection cache render return a collection of rendered HTML strings?

I think you might be able to stitch the objects and their rendered HTML together like this:

    @posts.zip(render(partial: ’posts/post’, collection: @posts, cached: true))

Though overall, I don’t think we’re going to change the interface here. Thanks! :)

Den 5. mar. 2017 kl. 10.06 skrev Gleb Mazovetskiy <[hidden email]>:

You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].

To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.

--
Kasper

--
You received this message because you are subscribed to a topic in the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/rubyonrails-core/Cx0GXz_k7Dc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Collection caching: render to strings

Kasper Hansen
Right, it’s joined with the spacer template. Maybe that’s usable?


Den 20. mar. 2017 kl. 21.44 skrev Gleb Mazovetskiy <[hidden email]>:

No, a collection cache render returns a single string.


On Mon, 20 Mar 2017, 19:15 Kasper Timm Hansen, <[hidden email]> wrote:
Been a while since I’ve last worked with that code but doesn’t a collection cache render return a collection of rendered HTML strings?

I think you might be able to stitch the objects and their rendered HTML together like this:

    @posts.zip(render(partial: ’posts/post’, collection: @posts, cached: true))

Though overall, I don’t think we’re going to change the interface here. Thanks! :)

Den 5. mar. 2017 kl. 10.06 skrev Gleb Mazovetskiy <[hidden email]>:

You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].

To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.

--
Kasper


--
You received this message because you are subscribed to a topic in the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/rubyonrails-core/Cx0GXz_k7Dc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.

--
Kasper

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Collection caching: render to strings

GlebM
If you mean whether cache_collection_render is usable, I think it would be but it is currently private!

The implementation I've linked to above does use PartialRenderer, and effectively reimplements cache_collection_render using only public APIs.

On Tue, Mar 21, 2017 at 6:45 PM Kasper Timm Hansen <[hidden email]> wrote:

Den 20. mar. 2017 kl. 21.44 skrev Gleb Mazovetskiy <[hidden email]>:

No, a collection cache render returns a single string.


On Mon, 20 Mar 2017, 19:15 Kasper Timm Hansen, <[hidden email]> wrote:
Been a while since I’ve last worked with that code but doesn’t a collection cache render return a collection of rendered HTML strings?

I think you might be able to stitch the objects and their rendered HTML together like this:

    @posts.zip(render(partial: ’posts/post’, collection: @posts, cached: true))

Though overall, I don’t think we’re going to change the interface here. Thanks! :)

Den 5. mar. 2017 kl. 10.06 skrev Gleb Mazovetskiy <[hidden email]>:

You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].

To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.

--
Kasper


--
You received this message because you are subscribed to a topic in the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/rubyonrails-core/Cx0GXz_k7Dc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.

--
Kasper

--
You received this message because you are subscribed to a topic in the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/rubyonrails-core/Cx0GXz_k7Dc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.
Loading...