[TikiWiki-commits] [Git][tikiwiki/tiki][29.x] [FIX] List plugin: specify count-only queries to allow faster retrieval on report pages

"Victor Emanouilov \(@kroky\) via TikiWiki-cvs" <[email protected]>
Newsgroups gmane.comp.cms.tiki.cvs
Message-ID <695e62d28a329_2c1a791c7292b@gitlab-sidekiq-low-urgency-cpu-bound-v2-7dd748c866-vblhz.mail>

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


Commits:
81647808 by Victor Emanouilov at 2026-01-07T15:42:31+02:00
[FIX] List plugin: specify count-only queries to allow faster retrieval on report pages
---
* [FIX] ignore list update

* [FIX] List plugin: specify count-only queries to allow faster retrieval on report pages

See merge request tikiwiki/tiki!9316

- - - - -


7 changed files:

- doc/devtools/codesniffer/standards/TikiIgnore/ignore_list.json
- lib/core/Search/Elastic/Index.php
- lib/core/Search/Manticore/Index.php
- lib/core/Search/Manticore/PdoClient.php
- lib/core/Search/MySql/Index.php
- lib/core/Search/Query.php
- lib/core/Search/Query/WikiBuilder.php


Changes:

=====================================
doc/devtools/codesniffer/standards/TikiIgnore/ignore_list.json
=====================================
@@ -6902,6 +6902,7 @@
             "Search_Query_WikiBuilder::wpquery_pagination_sort_arg": true,
             "Search_Query_WikiBuilder::wpquery_pagination_max": true,
             "Search_Query_WikiBuilder::wpquery_select_fields": true,
+            "Search_Query_WikiBuilder::wpquery_select_count": true,
             "Search_Query_WikiBuilder::wpquery_group_boost": true,
             "Search_Query_WikiBuilder::wpquery_index_federated": true,
             "Search_Query_WikiBuilder::get_fields_from_arguments": true


=====================================
lib/core/Search/Elastic/Index.php
=====================================
@@ -502,6 +502,10 @@ class Search_Elastic_Index implements Search_Index_Interface, Search_Index_Query
             $hits->total = $hits->total->value;
         }
 
+        if ($query->isCountOnly()) {
+            return new Search_Elastic_ResultSet([], $hits->total, $resultStart, $resultCount);
+        }
+
         if ($query->processDidYouMean() && $hits->total === 0) {
             list($result, $correctKeywords, $didYouMean) = $this->callSuggestions([
                 'fullQuery' => $fullQuery,


=====================================
lib/core/Search/Manticore/Index.php
=====================================
@@ -440,6 +440,11 @@ class Index implements \Search_Index_Interface, \Search_Index_QueryRepository
             $table = $this->index;
         }
 
+        if ($query->isCountOnly()) {
+            $totalCount = $this->pdo_client->count($table, $condition);
+            return new ResultSet([], $totalCount, $resultStart, $resultCount);
+        }
+
         $builder = new OrderBuilder($this);
         $order = $builder->build($query->getSortOrder());
 


=====================================
lib/core/Search/Manticore/PdoClient.php
=====================================
@@ -384,6 +384,26 @@ class PdoClient
         return $stmt->fetchAll();
     }
 
+    public function count($table, $condition, $retry = true)
+    {
+        $stmt = null;
+        try {
+            $stmt = $this->query("SELECT COUNT(*) FROM $table WHERE $condition option not_terms_only_allowed=1,cutoff=0,expand_keywords=1");
+            return intval($stmt->fetchColumn());
+        } catch (PDOException $e) {
+            if ($retry && strstr($e->getMessage(), 'unknown local table')) {
+                if ($stmt) {
+                    $stmt->closeCursor();
+                }
+                // federated index tables might have been rebuilt and distributed one not updated properly -> refresh and retry
+                \TikiLib::lib('federatedsearch')->recreateDistributedIndex($this);
+                return $this->count($table, $condition, false);
+            } else {
+                throw $e;
+            }
+        }
+    }
+
     /**
      * Fetches results from the index along with any facets data that come as subsequent row sets.
      * Builds the query and fetches the results in 2 parts to reduce memory footprint and performance impact for big indices (say 1000+ fields):


=====================================
lib/core/Search/MySql/Index.php
=====================================
@@ -171,6 +171,11 @@ class Search_MySql_Index implements Search_Index_Interface
                 $this->table->expr($condition),
             ];
 
+            if ($query->isCountOnly()) {
+                $totalCount = $this->table->fetchCount($conditions);
+                return new Search_ResultSet([], $totalCount, $resultStart, $resultCount);
+            }
+
             $scoreFields = [];
             $indexes = $this->builder->getRequiredIndexes();
             foreach ($indexes as $index) {


=====================================
lib/core/Search/Query.php
=====================================
@@ -14,6 +14,7 @@ class Search_Query implements Search_Query_Interface
     private $weightCalculator = null;
     private $identifierFields = null;
     private $selectionFields = null;
+    private $countOnly = false;
 
     private $postFilter;
     private $processDidYouMean = false;
@@ -71,6 +72,16 @@ class Search_Query implements Search_Query_Interface
         return $this->cyphtSearch;
     }
 
+    public function setCountOnly($countOnly = true)
+    {
+        $this->countOnly = (bool) $countOnly;
+    }
+
+    public function isCountOnly()
+    {
+        return $this->countOnly;
+    }
+
     public function addObject($type, $objectId)
     {
         if (is_null($this->objectList)) {


=====================================
lib/core/Search/Query/WikiBuilder.php
=====================================
@@ -129,6 +129,11 @@ class Search_Query_WikiBuilder
         $query->setSelectionFields(preg_split('/[, ]+/', $value));
     }
 
+    public function wpquery_select_count($query, $value)
+    {
+        $query->setCountOnly(true);
+    }
+
     public function wpquery_filter_editable($query, $editableType, array $arguments)
     {
         $fields = $this->get_fields_from_arguments($arguments);



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

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