Issue 73: Changes for real-time markup
Status:  Fixed
Owner:
Closed:  Aug 2009
Reported by byme...@gmail.com, Aug 6, 2009
Hola people :)

Everytime a thread is viewed the tag {% load markup %} is executed, so
markup is loaded.

Then markdown works for every post in {{ post.body|markdown }}
What's the problem with this?

Well, this is a tool which has a coputational cost. Imagine that we have a
thousand of people viewing posts at the same time and our machine has
limited resources. It could be a big problem if our server has to render
hundreds and hundreds of posts every minute.


My proposal is about changing this behaviour, so that the conversion to
HTML only takes place when a new post is saved (or modified by admin).

The problem:
it breaks the existing model, so if someone wants to change from old to the
new version has to apply the next message steps.

it consists in adding to Class Post the following in the model.py
    body_html = models.TextField(editable=False)

and then in save() method add:
        self.body_html = markdown(self.body)

so now we render comments like {{ post.body_html|safe }}, which hasn't got
almost no computational cost.


As I said, computing costs are limited and expensive, while harddrive space
isn't a problem nowadays.
In the next message a little help for old installations.

Thanks for reading,
Rafa Muñoz Cárdenas
models.patch
1.1 KB   View   Download
thread.patch
766 bytes   View   Download
Aug 6, 2009
#1 byme...@gmail.com
How to make the new model work and export old messages:

$ mysql -u root -p
mysql> use yourdbname;
mysql> ALTER TABLE forum_post ADD COLUMN body_html longtext;
mysql> UPDATE forum_post SET body_html='Empty!';
mysql> exit


$ python manage.py shell

>>> from markdown import markdown
>>> from forum.models import Post
>>> 
>>> for post in Post.objects.all():
...     post.body_html = markdown(post.body)
...     post.save()
... 
>>> exit()

Aug 27, 2009
Project Member #2 rwpoul...@gmail.com
Added in SVN r52. Thanks!

Existing users will need to update their database as mentioned above (and in the
README file)
Status: Fixed
Owner: rwpoulton
Labels: -Type-Defect Type-Enhancement