kmpekala / django-forum

Automatically exported from code.google.com/p/django-forum
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

Changes for real-time markup #73

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
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

Original issue reported on code.google.com by byme...@gmail.com on 6 Aug 2009 at 10:54

Attachments:

GoogleCodeExporter commented 8 years ago
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()

Original comment by byme...@gmail.com on 6 Aug 2009 at 10:55

GoogleCodeExporter commented 8 years ago
Added in SVN r52. Thanks!

Existing users will need to update their database as mentioned above (and in the
README file)

Original comment by rwpoul...@gmail.com on 27 Aug 2009 at 10:08