[TikiWiki-commits] [Git][tikiwiki/tiki][master] [ENH] ItemsList optimization when rebuilding

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

Victor Emanouilov pushed to branch master at Tiki Wiki CMS Groupware / Tiki


Commits:
d75c8a53 by Victor Emanouilov at 2025-11-25T13:21:36+00: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
=====================================
@@ -332,12 +332,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 [
@@ -866,7 +866,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');
@@ -900,10 +900,11 @@ $("input[name=ins_' . $this->getOption('fieldIdHere') . '], select[name=ins_' .
                     $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
=====================================
@@ -835,10 +835,10 @@ class TrackerLib extends TikiLib
         }
 
         $query = "
-          SELECT tiki_trackers.*, 
+          SELECT tiki_trackers.*,
           COUNT(tiki_tracker_fields.fieldId) AS fieldsCount
           FROM tiki_trackers
-          LEFT JOIN tiki_tracker_fields 
+          LEFT JOIN tiki_tracker_fields
           ON tiki_trackers.trackerId = tiki_tracker_fields.trackerId
           $join
           WHERE 1=1 $where
@@ -949,13 +949,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) {
@@ -1001,6 +1008,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;
     }
 
@@ -4083,9 +4096,16 @@ 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
     {
-        $query = "SELECT tif.`value`, tf.`type` 
+        if ($use_cache) {
+            static $cache = [];
+            $cacheKey = "isMain_value_{$trackerId}_{$itemId}";
+            if (isset($cache[$cacheKey])) {
+                return $cache[$cacheKey];
+            }
+        }
+        $query = "SELECT tif.`value`, tf.`type`
                 FROM `tiki_tracker_item_fields` tif
                 JOIN `tiki_tracker_items` i ON i.`itemId` = tif.`itemId`
                 JOIN `tiki_tracker_fields` tf ON tf.`fieldId` = tif.`fieldId`
@@ -4108,7 +4128,14 @@ class TrackerLib extends TikiLib
                 $titles[] = $value;
             }
         }
-        return implode(' ', $titles);
+        $result = implode(' ', $titles);
+        if ($use_cache) {
+            if (TikiLib::lib('tiki')->isMemoryLow()) {
+                $cache = [];
+            }
+            $cache[$cacheKey] = $result;
+        }
+        return $result;
     }
     /**
      * @param int $itemId



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

-- 
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/d75c8a53dfc9a03fbd780ae31842f35fac25a2a8
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.