]> git.mxchange.org Git - friendica.git/commitdiff
Fill the item cache when storing item
authorMichael <heluecht@pirati.ca>
Wed, 4 May 2022 06:17:34 +0000 (06:17 +0000)
committerMichael <heluecht@pirati.ca>
Wed, 4 May 2022 06:17:34 +0000 (06:17 +0000)
src/Model/Item.php

index 96a12a1fd3d6563cc025ad8e7e1bc4d7013c6c70..3ff7909aa1729f3a66ae83827f4ad30b0de5ff02 100644 (file)
@@ -1215,9 +1215,26 @@ class Item
                        Worker::add(['priority' => $priority, 'dont_fork' => true], 'Notifier', $notify_type, (int)$posted_item['uri-id'], (int)$posted_item['uid']);
                }
 
+               // Fill the cache with the rendered content.
+               if (in_array($posted_item['gravity'], [GRAVITY_PARENT, GRAVITY_COMMENT]) && ($posted_item['uid'] == 0)) {
+                       self::updateDisplayCache($posted_item['uri-id']);
+               }
+
                return $post_user_id;
        }
 
+       /**
+        * Update the display cache
+        *
+        * @param integer $uri_id
+        * @return void
+        */
+       public static function updateDisplayCache(int $uri_id)
+       {
+               $item = Post::selectFirst(self::DISPLAY_FIELDLIST, ['uri-id' => $uri_id]);
+               self::prepareBody($item, false, false, true);
+       }
+
        /**
         * Change the owner of a parent item if it had been shared by a forum
         *
@@ -2763,6 +2780,7 @@ class Item
         * @param array   $item
         * @param boolean $attach
         * @param boolean $is_preview
+        * @param boolean $only_cache
         * @return string item body html
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         * @throws \ImagickException
@@ -2771,7 +2789,7 @@ class Item
         * @hook  prepare_body ('item'=>item array, 'html'=>body string, 'is_preview'=>boolean, 'filter_reasons'=>string array) after first bbcode to html
         * @hook  prepare_body_final ('item'=>item array, 'html'=>body string) after attach icons and blockquote special case handling (spoiler, author)
         */
-       public static function prepareBody(array &$item, $attach = false, $is_preview = false)
+       public static function prepareBody(array &$item, $attach = false, $is_preview = false, $only_cache = false)
        {
                $a = DI::app();
                Hook::callAll('prepare_body_init', $item);
@@ -2812,6 +2830,10 @@ class Item
                $item['body'] = $body;
                $s = $item["rendered-html"];
 
+               if ($only_cache) {
+                       return;
+               }
+
                // Compile eventual content filter reasons
                $filter_reasons = [];
                if (!$is_preview && public_contact() != $item['author-id']) {