PERF: Cache emojified post content

This commit is contained in:
Toby Zerner 2015-07-31 20:32:49 +09:30
parent cb358a9084
commit 637e3abfc9

View File

@ -5,8 +5,15 @@ import app from 'flarum/app';
import Post from 'flarum/models/Post';
app.initializers.add('emoji', () => {
override(Post.prototype, 'contentHtml', original => {
return twemoji.parse(original());
override(Post.prototype, 'contentHtml', function(original) {
const contentHtml = original();
if (this.oldContentHtml !== contentHtml) {
this.emojifiedContentHtml = twemoji.parse(contentHtml);
this.oldContentHtml = contentHtml;
}
return this.emojifiedContentHtml;
});
override(s9e.TextFormatter, 'preview', (original, text, element) => {