From f97e1b53098941ec4cd52ec1704d7a945bd65a12 Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Sun, 23 Nov 2014 05:16:21 -0500 Subject: [PATCH] Performance: skip SELECT COUNT(*) query in case when result contains less records than page size --- plugins/kolab_addressbook/lib/rcube_kolab_contacts.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/plugins/kolab_addressbook/lib/rcube_kolab_contacts.php b/plugins/kolab_addressbook/lib/rcube_kolab_contacts.php index 3b4a3f6a..fa215834 100644 --- a/plugins/kolab_addressbook/lib/rcube_kolab_contacts.php +++ b/plugins/kolab_addressbook/lib/rcube_kolab_contacts.php @@ -365,7 +365,14 @@ class rcube_kolab_contacts extends rcube_addressbook } } else if (isset($this->dataset)) { - $this->result->count = isset($query) ? $this->storagefolder->count($query) : 0; + // get all records count, skip the query if possible + if (!isset($query) || count($this->dataset) < $this->page_size) { + $this->result->count = count($this->dataset) + $this->page_size * ($this->list_page - 1); + } + else { + $this->result->count = $this->storagefolder->count($query); + } + foreach ($this->dataset as $idx => $record) { $this->result->add($this->_to_rcube_contact($record)); }