[TikiWiki-commits] [Git][tikiwiki/tiki][master] [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 | <695e625d6becc_2c77148d010718@gitlab-sidekiq-low-urgency-cpu-bound-v2-7dd748c866-vnp8j.mail> |
Victor Emanouilov pushed to branch master at Tiki Wiki CMS Groupware / Tiki
Commits:
ad2620cc by Victor Emanouilov at 2026-01-07T13:32:13+00: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
=====================================
@@ -5349,6 +5349,7 @@
"lib\/core\/Search\/Query\/WikiBuilder.php": {
"Search_Query_WikiBuilder::wpquery_list_max": true,
"Search_Query_WikiBuilder::wpquery_select_fields": true,
+ "Search_Query_WikiBuilder::wpquery_select_count": true,
"Search_Query_WikiBuilder::wpquery_filter_editable": true,
"Search_Query_WikiBuilder::wpquery_sort_return_only": true,
"Search_Query_WikiBuilder::wpquery_filter_type": 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/ad2620cc4eef9cb8e1ff736f908076b00a0f4b64
--
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/ad2620cc4eef9cb8e1ff736f908076b00a0f4b64
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