From d8f72b729bb1a5255f0edccc2375e878bd16d5f2 Mon Sep 17 00:00:00 2001 From: flashwave Date: Fri, 7 Oct 2016 18:06:07 +0200 Subject: [PATCH] Store parsed bbcode --- app/Forum/Post.php | 13 ++++--- .../2016_10_07_174622_cache_parsed_bbcode.php | 34 +++++++++++++++++++ 2 files changed, 43 insertions(+), 4 deletions(-) create mode 100644 database/2016_10_07_174622_cache_parsed_bbcode.php diff --git a/app/Forum/Post.php b/app/Forum/Post.php index 5195759..dcdeba4 100644 --- a/app/Forum/Post.php +++ b/app/Forum/Post.php @@ -71,7 +71,7 @@ class Post * The parsed contents of this post. * @var string */ - public $parsed = ""; + public $parsed = null; /** * The UNIX timestamp of the last time this post was edited. @@ -117,6 +117,7 @@ class Post $this->time = intval($postRow->post_time); $this->subject = $postRow->post_subject; $this->text = $postRow->post_text; + $this->parsed = $postRow->post_text_parsed; $this->editTime = intval($postRow->post_edit_time); $this->editReason = $postRow->post_edit_reason; $this->editUser = User::construct($postRow->post_edit_user); @@ -129,10 +130,12 @@ class Post $this->ip = $postRow->poster_ip; $this->update(); } - } - // Parse the markup - $this->parsed = BBParser::toHTML(htmlentities($this->text)); + if (strlen($this->parsed) < 1) { + $this->parsed = BBParser::toHTML(htmlentities($this->text)); + $this->update(); + } + } } /** @@ -168,6 +171,7 @@ class Post 'post_time' => time(), 'post_subject' => $subject, 'post_text' => $text, + 'post_text_parsed' => BBParser::toHTML(htmlentities($text)), ]); // Update the last post date @@ -197,6 +201,7 @@ class Post 'post_time' => $this->time, 'post_subject' => $this->subject, 'post_text' => $this->text, + 'post_text_parsed' => BBParser::toHTML(htmlentities($this->text)), 'post_edit_time' => $this->editTime, 'post_edit_reason' => $this->editReason, 'post_edit_user' => $this->editUser->id, diff --git a/database/2016_10_07_174622_cache_parsed_bbcode.php b/database/2016_10_07_174622_cache_parsed_bbcode.php new file mode 100644 index 0000000..3c76e56 --- /dev/null +++ b/database/2016_10_07_174622_cache_parsed_bbcode.php @@ -0,0 +1,34 @@ +table('posts', function (Blueprint $table) { + $table->text('post_text_parsed') + ->nullable(); + }); + } + + /** + * Reverse the migrations. + * @return void + */ + public function down() + { + $schema = DB::getSchemaBuilder(); + + $schema->table('posts', function (Blueprint $table) { + $table->dropColumn('post_text_parsed'); + }); + } +}