Drop pre-rendered html: MediaComment.content_html
authorElrond <elrond+mediagoblin.org@samba-tng.org>
Sat, 18 Feb 2012 10:32:28 +0000 (11:32 +0100)
committerElrond <elrond+mediagoblin.org@samba-tng.org>
Sat, 18 Feb 2012 11:50:30 +0000 (12:50 +0100)
After a bit of discussion, we decided to drop the
pre-rendered html from the database and render it on
the fly.

In another step, we will use some proper caching method to
cache this stuff.

This commit affects the MediaComment.content_html part.

mediagoblin/db/mixin.py
mediagoblin/db/mongo/migrations.py
mediagoblin/db/mongo/models.py
mediagoblin/db/sql/convert.py
mediagoblin/db/sql/models.py
mediagoblin/user_pages/views.py

index 4e3800ab7b4e9bbb0900d37d45158f4072983551..758f7e72dee98ab513a3df705815bd2b0a5511da 100644 (file)
@@ -104,3 +104,13 @@ class MediaEntryMixin(object):
     def get_license_data(self):
         """Return license dict for requested license"""
         return licenses.SUPPORTED_LICENSES[self.license or ""]
+
+
+class MediaCommentMixin(object):
+    @property
+    def content_html(self):
+        """
+        the actual html-rendered version of the comment displayed.
+        Run through Markdown and the HTML cleaner.
+        """
+        return cleaned_markdown_conversion(self.content)
index 57da7dd895880b7dbe741e897ef147bb4080e2a7..59035f3b44496bff2125c08031e13f06615fcb12 100644 (file)
@@ -130,7 +130,12 @@ def mediaentry_add_license(database):
 @RegisterMigration(9)
 def remove_calculated_html(database):
     """
-    Drop bio_html, description_html again and calculate things on the fly (and cache)
+    Drop pre-rendered html again and calculate things
+    on the fly (and cache):
+    - User.bio_html
+    - MediaEntry.description_html
+    - MediaComment.content_html
     """
     drop_table_field(database, 'users', 'bio_html')
     drop_table_field(database, 'media_entries', 'description_html')
+    drop_table_field(database, 'media_comments', 'content_html')
index db38d502686bccfaf465d097f8cece44bd52be70..57af137dd23afcf0a2a087ed3796a4f49df6900c 100644 (file)
@@ -23,7 +23,7 @@ from mediagoblin.db.mongo import migrations
 from mediagoblin.db.mongo.util import ASCENDING, DESCENDING, ObjectId
 from mediagoblin.tools.pagination import Pagination
 from mediagoblin.tools import url
-from mediagoblin.db.mixin import UserMixin, MediaEntryMixin
+from mediagoblin.db.mixin import UserMixin, MediaEntryMixin, MediaCommentMixin
 
 ###################
 # Custom validators
@@ -251,7 +251,7 @@ class MediaEntry(Document, MediaEntryMixin):
         return self.db.User.find_one({'_id': self.uploader})
 
 
-class MediaComment(Document):
+class MediaComment(Document, MediaCommentMixin):
     """
     A comment on a MediaEntry.
 
@@ -260,8 +260,6 @@ class MediaComment(Document):
      - author: user who posted this comment
      - created: when the comment was created
      - content: plaintext (but markdown'able) version of the comment's content.
-     - content_html: the actual html-rendered version of the comment displayed.
-       Run through Markdown and the HTML cleaner.
     """
 
     __collection__ = 'media_comments'
@@ -272,7 +270,7 @@ class MediaComment(Document):
         'author': ObjectId,
         'created': datetime.datetime,
         'content': unicode,
-        'content_html': unicode}
+        }
 
     required_fields = [
         'media_entry', 'author', 'created', 'content']
index 9d27686636a0574129581304a9300985947f1910..a46d62ea35e48d280dc226883da82c7e20e97bad 100644 (file)
@@ -133,7 +133,7 @@ def convert_media_comments(mk_db):
         new_entry = MediaComment()
         copy_attrs(entry, new_entry,
             ('created',
-             'content', 'content_html',))
+             'content',))
         copy_reference_attr(entry, new_entry, "media_entry")
         copy_reference_attr(entry, new_entry, "author")
 
index 72591f4ef5e10c6a27f73c47df830f3fe049fb94..18e1dfd7453612d1d2704729a0371e6461482ce0 100644 (file)
@@ -31,7 +31,7 @@ from sqlalchemy.ext.associationproxy import association_proxy
 
 from mediagoblin.db.sql.extratypes import PathTupleWithSlashes
 from mediagoblin.db.sql.base import Base, DictReadAttrProxy
-from mediagoblin.db.mixin import UserMixin, MediaEntryMixin
+from mediagoblin.db.mixin import UserMixin, MediaEntryMixin, MediaCommentMixin
 
 
 class SimpleFieldAlias(object):
@@ -218,7 +218,7 @@ class MediaTag(Base):
         return DictReadAttrProxy(self)
 
 
-class MediaComment(Base):
+class MediaComment(Base, MediaCommentMixin):
     __tablename__ = "media_comments"
 
     id = Column(Integer, primary_key=True)
@@ -227,7 +227,6 @@ class MediaComment(Base):
     author = Column(Integer, ForeignKey('users.id'), nullable=False)
     created = Column(DateTime, nullable=False, default=datetime.datetime.now)
     content = Column(UnicodeText, nullable=False)
-    content_html = Column(UnicodeText)
 
     get_author = relationship(User)
 
index 46435d8156a782d97783951cc08d9e76a4dd22de..05d07b1bfe5134333a756b2c29199eec24ede38d 100644 (file)
@@ -18,7 +18,6 @@ from webob import exc
 
 from mediagoblin import messages, mg_globals
 from mediagoblin.db.util import DESCENDING, ObjectId
-from mediagoblin.tools.text import cleaned_markdown_conversion
 from mediagoblin.tools.response import render_to_response, render_404, redirect
 from mediagoblin.tools.translate import pass_to_ugettext as _
 from mediagoblin.tools.pagination import Pagination
@@ -146,7 +145,6 @@ def media_post_comment(request, media):
     comment['media_entry'] = media._id
     comment['author'] = request.user._id
     comment['content'] = unicode(request.POST['comment_content'])
-    comment['content_html'] = cleaned_markdown_conversion(comment['content'])
 
     if not comment['content'].strip():
         messages.add_message(