Drop pre-rendered html: MediaEntry.description_html
authorElrond <elrond+mediagoblin.org@samba-tng.org>
Mon, 13 Feb 2012 12:42:59 +0000 (13:42 +0100)
committerElrond <elrond+mediagoblin.org@samba-tng.org>
Sat, 18 Feb 2012 11:41:25 +0000 (12:41 +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 MediaEntry.description_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/edit/views.py
mediagoblin/listings/views.py
mediagoblin/submit/views.py
mediagoblin/user_pages/views.py

index 2ff08722e3a0f98ee14d34070a148091395fb496..4e3800ab7b4e9bbb0900d37d45158f4072983551 100644 (file)
@@ -46,6 +46,14 @@ class UserMixin(object):
 
 
 class MediaEntryMixin(object):
+    @property
+    def description_html(self):
+        """
+        Rendered version of the description, run through
+        Markdown and cleaned with our cleaning tool.
+        """
+        return cleaned_markdown_conversion(self.description)
+
     def get_display_media(self, media_map,
                           fetch_order=common.DISPLAY_IMAGE_FETCHING_ORDER):
         """
index 74a810c1eb447c2e078dae4df69651facd210f9f..57da7dd895880b7dbe741e897ef147bb4080e2a7 100644 (file)
@@ -29,6 +29,16 @@ def add_table_field(db, table_name, field_name, default_value):
         multi=True)
 
 
+def drop_table_field(db, table_name, field_name):
+    """
+    Drop an old field from a table/collection
+    """
+    db[table_name].update(
+        {field_name: {'$exists': True}},
+        {'$unset': {field_name: 1}},
+        multi=True)
+
+
 # Please see mediagoblin/tests/test_migrations.py for some examples of
 # basic migrations.
 
@@ -118,11 +128,9 @@ def mediaentry_add_license(database):
 
 
 @RegisterMigration(9)
-def user_remove_bio_html(database):
+def remove_calculated_html(database):
     """
-    Drop bio_html again and calculate things on the fly (and cache)
+    Drop bio_html, description_html again and calculate things on the fly (and cache)
     """
-    database['users'].update(
-        {'bio_html': {'$exists': True}},
-        {'$unset': {'bio_html': 1}},
-        multi=True)
+    drop_table_field(database, 'users', 'bio_html')
+    drop_table_field(database, 'media_entries', 'description_html')
index c1282f4ae7177181dbf06f8ea19f0c484a39efa0..db38d502686bccfaf465d097f8cece44bd52be70 100644 (file)
@@ -110,9 +110,6 @@ class MediaEntry(Document, MediaEntryMixin):
        up with MarkDown for slight fanciness (links, boldness, italics,
        paragraphs...)
 
-     - description_html: Rendered version of the description, run through
-       Markdown and cleaned with our cleaning tool.
-
      - media_type: What type of media is this?  Currently we only support
        'image' ;)
 
@@ -177,7 +174,6 @@ class MediaEntry(Document, MediaEntryMixin):
         'slug': unicode,
         'created': datetime.datetime,
         'description': unicode,  # May contain markdown/up
-        'description_html': unicode,  # May contain plaintext, or HTML
         'media_type': unicode,
         'media_data': dict,  # extra data relevant to this media_type
         'plugin_data': dict,  # plugins can dump stuff here.
index a098927ff73b1d135a6d1c8dca7883c356d4d415..9d27686636a0574129581304a9300985947f1910 100644 (file)
@@ -77,7 +77,7 @@ def convert_media_entries(mk_db):
         new_entry = MediaEntry()
         copy_attrs(entry, new_entry,
             ('title', 'slug', 'created',
-             'description', 'description_html',
+             'description',
              'media_type', 'state', 'license',
              'fail_error',
              'queued_task_id',))
index 3cf4ff40957dbbe184ecd1f9f97a5e60e15ca479..72591f4ef5e10c6a27f73c47df830f3fe049fb94 100644 (file)
@@ -85,7 +85,6 @@ class MediaEntry(Base, MediaEntryMixin):
     slug = Column(Unicode)
     created = Column(DateTime, nullable=False, default=datetime.datetime.now)
     description = Column(UnicodeText) # ??
-    description_html = Column(UnicodeText) # ??
     media_type = Column(Unicode, nullable=False)
     state = Column(Unicode, default=u'unprocessed', nullable=False)
         # or use sqlalchemy.types.Enum?
index 47761f23f4cfbf5636b2e0d83d20b968783b856b..3df36e8ebc4953b317e8b23f393eb5f87a1428d4 100644 (file)
@@ -34,7 +34,7 @@ from mediagoblin.tools.response import render_to_response, redirect
 from mediagoblin.tools.translate import pass_to_ugettext as _
 from mediagoblin.tools.text import (
     clean_html, convert_to_tag_list_of_dicts,
-    media_tags_as_string, cleaned_markdown_conversion)
+    media_tags_as_string)
 from mediagoblin.tools.licenses import SUPPORTED_LICENSES
 
 
@@ -72,9 +72,6 @@ def edit_media(request, media):
             media.tags = convert_to_tag_list_of_dicts(
                                    request.POST.get('tags'))
 
-            media.description_html = cleaned_markdown_conversion(
-                media.description)
-
             media.license = unicode(request.POST.get('license', '')) or None
 
             media.slug = unicode(request.POST['slug'])
index 48320cb2de48016ebd60cf01df739c4b632474b0..ba23fc46b6b93336e2e50f4a55e3a6efbfd631aa 100644 (file)
@@ -91,7 +91,7 @@ def tag_atom_feed(request):
             'type': 'text/html'}])
     for entry in cursor:
         feed.add(entry.get('title'),
-            entry.get('description_html'),
+            entry.description_html,
             id=entry.url_for_self(request.urlgen,qualified=True),
             content_type='html',
             author={'name': entry.get_uploader.username,
index cdd097ecc5c0f71af1024de99e72fb083a819d3b..845400caaec04fc708a487b6f93eb442e4d1e890 100644 (file)
@@ -28,7 +28,7 @@ _log = logging.getLogger(__name__)
 from werkzeug.utils import secure_filename
 
 from mediagoblin.db.util import ObjectId
-from mediagoblin.tools.text import cleaned_markdown_conversion, convert_to_tag_list_of_dicts
+from mediagoblin.tools.text import convert_to_tag_list_of_dicts
 from mediagoblin.tools.translate import pass_to_ugettext as _
 from mediagoblin.tools.response import render_to_response, redirect
 from mediagoblin.decorators import require_active_login
@@ -66,8 +66,6 @@ def submit_start(request):
                     or unicode(splitext(filename)[0]))
 
                 entry.description = unicode(request.POST.get('description'))
-                entry.description_html = cleaned_markdown_conversion(
-                    entry.description)
 
                 entry.license = unicode(request.POST.get('license', "")) or None
 
index 82791278b31a495953e59348d9e93f488263c29b..46435d8156a782d97783951cc08d9e76a4dd22de 100644 (file)
@@ -250,7 +250,7 @@ def atom_feed(request):
 
     for entry in cursor:
         feed.add(entry.get('title'),
-            entry.get('description_html'),
+            entry.description_html,
             id=entry.url_for_self(request.urlgen,qualified=True),
             content_type='html',
             author={