Convert markdown to HTML on demand
We were converting markdown to HTML every time we saved a record, which has the same problems as sanitizing HTML before saving it to the database, particularly because the body of a legislation draft is stored in a translations table. Performance-wise this isn't a problem: converting a text with more than 200_000 characters takes about a milisecond on my machine. Note we need to modify a migration generated by globalize, since the method `create_translation_table!` would fail now that we don't define `translates :body_html` in the model.
This commit is contained in:
@@ -20,12 +20,14 @@ class AddCollaborativeLegislationTranslations < ActiveRecord::Migration[4.2]
|
||||
{
|
||||
title: :string,
|
||||
changelog: :text,
|
||||
body: :text,
|
||||
body_html: :text,
|
||||
toc_html: :text
|
||||
body: :text
|
||||
},
|
||||
{ migrate_data: true }
|
||||
)
|
||||
|
||||
add_column :legislation_draft_version_translations, :body_html, :text
|
||||
add_column :legislation_draft_version_translations, :toc_html, :text
|
||||
|
||||
Legislation::QuestionOption.create_translation_table!(
|
||||
{ value: :string },
|
||||
{ migrate_data: true }
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
class RemoveHtmlFieldsFormLegislationDraftVersion < ActiveRecord::Migration[5.0]
|
||||
def change
|
||||
remove_column :legislation_draft_versions, :body_html
|
||||
remove_column :legislation_draft_version_translations, :body_html
|
||||
remove_column :legislation_draft_versions, :toc_html
|
||||
remove_column :legislation_draft_version_translations, :toc_html
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user