[TikiWiki-commits] [Git][tikiwiki/tiki][28.x] [ENH] ItemsList optimization when rebuilding

"Victor Emanouilov \(@kroky\) via TikiWiki-cvs" <[email protected]>
Newsgroups gmane.comp.cms.tiki.cvs
Message-ID <6925b0368df4f_2a1336f0c8389f@gitlab-sidekiq-low-urgency-cpu-bound-v2-7877566998-fvq9h.mail>

Victor Emanouilov pushed to branch 28.x at Tiki Wiki CMS Groupware / Tiki


Commits:
44f9db57 by Victor Emanouilov at 2025-11-25T15:33:33+02:00
[ENH] ItemsList optimization when rebuilding
---
* [ENH] ItemsList optimization when rebuilding - cache item labels and main item titles used to populate itemslist fields

See merge request tikiwiki/tiki!9115

- - - - -


2 changed files:

- lib/core/Tracker/Field/ItemsList.php
- lib/trackers/trackerlib.php


Changes:

=====================================
lib/core/Tracker/Field/ItemsList.php
=====================================
@@ -335,12 +335,12 @@ $("input[name=ins_' . $this->getOption('fieldIdHere') . '], select[name=ins_' .
         return parent::watchCompare($o, $n);    // then compare as text
     }
 
-    public function getDocumentPart(Search_Type_Factory_Interface $typeFactory)
+    public function getDocumentPart(Search_Type_Factory_Interface $typeFactory, $mode = '')
     {
         $baseKey = $this->getBaseKey();
         $items = $this->getItemIds(false);
 
-        $list = $this->getItemLabels($items);
+        $list = $this->getItemLabels($items, ['list_mode' => ''], $mode);
         $listtext = implode(' ', $list);
 
         return [
@@ -869,7 +869,7 @@ $("input[name=ins_' . $this->getOption('fieldIdHere') . '], select[name=ins_' .
      * @param array $context
      * @return array array of values by itemId
      */
-    private function getItemLabels($items, $context = ['list_mode' => ''])
+    private function getItemLabels($items, $context = ['list_mode' => ''], $mode = '')
     {
         $displayFields = $this->getOption('displayFieldIdThere');
         $trackerId = (int) $this->getOption('trackerId');
@@ -903,10 +903,11 @@ $("input[name=ins_' . $this->getOption('fieldIdHere') . '], select[name=ins_' .
                     isset($context['list_mode']) ? $context['list_mode'] : '',
                     $this->getOption('linkToItems'),
                     $this->getOption('displayFieldIdThereFormat'),
-                    $trklib->get_tracker_item($itemId)
+                    $trklib->get_tracker_item($itemId),
+                    $mode === 'indexing'
                 );
             } else {
-                $list[$itemId] = $trklib->get_isMain_value($trackerId, $itemId);
+                $list[$itemId] = $trklib->get_isMain_value($trackerId, $itemId, $mode === 'indexing');
             }
         }
 


=====================================
lib/trackers/trackerlib.php
=====================================
@@ -928,13 +928,20 @@ class TrackerLib extends TikiLib
         }
     }
 
-    public function concat_item_from_fieldslist($trackerId, $itemId, $fieldsId, $status = 'o', $separator = ' ', $list_mode = '', $strip_tags = false, $format = '', $item = [])
+    public function concat_item_from_fieldslist($trackerId, $itemId, $fieldsId, $status = 'o', $separator = ' ', $list_mode = '', $strip_tags = false, $format = '', $item = [], $use_cache = false)
     {
         $res = '';
         $values = [];
         if (is_string($fieldsId)) {
             $fieldsId = preg_split('/\|/', $fieldsId, -1, PREG_SPLIT_NO_EMPTY);
         }
+        if ($use_cache) {
+            static $cache = [];
+            $cacheKey = "concat_item_from_fieldslist_{$trackerId}_{$itemId}_{$fieldsId}_{$status}_{$separator}_{$list_mode}_{$strip_tags}_{$format}";
+            if (isset($cache[$cacheKey])) {
+                return $cache[$cacheKey];
+            }
+        }
         $definition = Tracker_Definition::get($trackerId);
         if ($definition) {
             foreach ($fieldsId as $k => $field) {
@@ -980,6 +987,12 @@ class TrackerLib extends TikiLib
         } else {
             Feedback::error(tr('Tracker %0 not found for Field %1', $trackerId, implode(',', $fieldsId)));
         }
+        if ($use_cache) {
+            if (TikiLib::lib('tiki')->isMemoryLow()) {
+                $cache = [];
+            }
+            $cache[$cacheKey] = $res;
+        }
         return $res;
     }
 
@@ -4143,10 +4156,18 @@ class TrackerLib extends TikiLib
      * @param [type] $trackerId, optionnal (will be retrieved from itemId if missing)
      * @param [type] $itemId
      */
-    public function get_isMain_value($trackerId, $itemId): string
+    public function get_isMain_value($trackerId, $itemId, $use_cache = false): string
     {
         global $prefs;
 
+        if ($use_cache) {
+            static $cache = [];
+            $cacheKey = "isMain_value_{$trackerId}_{$itemId}";
+            if (isset($cache[$cacheKey])) {
+                return $cache[$cacheKey];
+            }
+        }
+
         $query = "select tif.`value` from `tiki_tracker_item_fields` tif, `tiki_tracker_items` i, `tiki_tracker_fields` tf where i.`itemId`=? and i.`itemId`=tif.`itemId` and tf.`fieldId`=tif.`fieldId` and tf.`isMain`=? ORDER BY tf.`position`";
         $queryResult = $this->getOne($query, [ (int) $itemId, "y"]);
         $result = $queryResult;
@@ -4192,14 +4213,22 @@ class TrackerLib extends TikiLib
             $decoded = json_decode($result, true);
             if ($decoded !== null) {     // might start with a "{" but may not be a json_encoded value
                 if (isset($decoded[$prefs['language']])) {
-                    return $decoded[$prefs['language']];
+                    $result = $decoded[$prefs['language']];
                 } elseif (is_array($decoded)) {
-                    return reset($decoded);
+                    $result = reset($decoded);
                 }
             }
         }
 
-        return (string) $result;
+        $result = (string) $result;
+
+        if ($use_cache) {
+            if (TikiLib::lib('tiki')->isMemoryLow()) {
+                $cache = [];
+            }
+            $cache[$cacheKey] = $result;
+        }
+        return $result;
     }
 
     /**



View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/44f9db57b452bab4d509bb55b71c0043de957f32

-- 
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/44f9db57b452bab4d509bb55b71c0043de957f32
You're receiving this email because of your account on gitlab.com.

_______________________________________________
TikiWiki-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tikiwiki-cvs
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.