[typo] body_html

Ioan Bizau jr. ib at sdf-eu.org
Mon Apr 25 17:22:32 EDT 2005


I didn't see how you do it in hieraki.
You have
def body_html
     HtmlEngine.transform(body)
end
in your model, which does the conversion on-the-fly. Do you make some magic?

Anyway, I have another solution. In the Article model use this:

---
@@bodies_html = {}

def body_html
	@@bodies_html[id] = HtmlEngine.transform(body) if @@bodies_html[id].nil?
	@@bodies_html[id]
end

before_save :clear_cache
def clear_cache
	@@bodies_html[id] = nil
end
---

Then drop the body_html column (huh) and delete this:
---
before_save :transform_body
def transform_body
	self.body_html = HtmlEngine.transform(body, self.text_filter)
end
---

Works for me. What do you think?

Tobias Luetke wrote:
> I left it in for this release so because of speed. Textilizing
> everything before display
> really is hard on the cpu. For the next release i look at statically
> caching every page of
> the blog (by moving the 42 minutes ago stuff to javascript ). I'll get
> rid of the _html business for sure at this point. In hieraki I already
> got rid of it and cache it in memory and it works fairly well as well
> so If you want you could look at how hieraki does it and submit a
> patch for typo.
> 
> 
> On 4/24/05, Jesse Andrews <anotherjesse at gmail.com> wrote:
> 
>>sure, just make a method to the Article that will convert to html
>>after you do the query and you are set...
>>
>>I personally like it since web blogs tend to be read more than edited.
>> Pre-computing the html optimizes for situtations like most blogs.
>>
>>If we built a more sophisticated caching mechanism (cache everything,
>>invalidating cached article reads when a comment/trackback is
>>added/removed or the article is edited, invalidating cached index when
>>an article is removed )
>>
>>Since Typo does the "42 minutes since ..." it would be necsesary to
>>not cache an article the first hour of its existance.  Once the
>>granulatity of the time goes up, you can cache for an hour by default
>>...
>>
>>Jesse
>>
>>On 4/24/05, Ioan Bizau jr. <ib at sdf-eu.org> wrote:
>>
>>>Once I asked Tobias about the two fields "body" and "body_html". He said
>>>that body_html is just an optimization and might be removed soon.
>>>It really bothers me, because it feels wet (anti-dry). Can't we just
>>>remove it?
>>>_______________________________________________
>>>Typo-list mailing list
>>>Typo-list at rubyforge.org
>>>http://rubyforge.org/mailman/listinfo/typo-list
>>>
>>
>>_______________________________________________
>>Typo-list mailing list
>>Typo-list at rubyforge.org
>>http://rubyforge.org/mailman/listinfo/typo-list
>>
> 
> 
> 


More information about the Typo-list mailing list