[TikiWiki-commits] [Git][tikiwiki/tiki][27.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 | <695e635feb660_2c18042064f@gitlab-sidekiq-low-urgency-cpu-bound-v2-7dd748c866-4fgmt.mail> |
Victor Emanouilov pushed to branch 27.x at Tiki Wiki CMS Groupware / Tiki
Commits:
9ad827f2 by Victor Emanouilov at 2026-01-07T15:44:55+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
=====================================
@@ -7198,6 +7198,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);
+ }
+
/**
* Sorted Search size adjustment (part 2) - Checks to see if the number of results returned
* are more than 500. If they are, set an approximate period filter to get to 500 results next
=====================================
lib/core/Search/Manticore/Index.php
=====================================
@@ -435,6 +435,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
=====================================
@@ -118,6 +118,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 $subQueries = [];
@@ -61,6 +62,16 @@ class Search_Query implements Search_Query_Interface
return $this->selectionFields;
}
+ 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/9ad827f23abf97402316c0e98e54a9b05795a6ef
--
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/9ad827f23abf97402316c0e98e54a9b05795a6ef
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