From 1f4df78b5fae3251b9c0c5617946ab959cad4cd2 Mon Sep 17 00:00:00 2001 From: tianhe1986 Date: Tue, 17 Jan 2017 15:07:09 +0800 Subject: Add aliased tables cache. Signed-off-by: tianhe1986 --- system/database/DB_query_builder.php | 40 +++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/system/database/DB_query_builder.php b/system/database/DB_query_builder.php index ab19d97a2..407b0d5d8 100644 --- a/system/database/DB_query_builder.php +++ b/system/database/DB_query_builder.php @@ -214,6 +214,13 @@ abstract class CI_DB_query_builder extends CI_DB_driver { */ protected $qb_cache_join = array(); + /** + * QB Cache aliased tables list data + * + * @var array + */ + protected $qb_cache_aliased_tables = array(); + /** * QB Cache WHERE data * @@ -2284,6 +2291,11 @@ abstract class CI_DB_query_builder extends CI_DB_driver { if ( ! in_array($table, $this->qb_aliased_tables)) { $this->qb_aliased_tables[] = $table; + if ($this->qb_caching === TRUE && ! in_array($table, $this->qb_cache_aliased_tables)) + { + $this->qb_cache_aliased_tables[] = $table; + $this->qb_cache_exists[] = 'aliased_tables'; + } } } } @@ -2616,16 +2628,17 @@ abstract class CI_DB_query_builder extends CI_DB_driver { public function flush_cache() { $this->_reset_run(array( - 'qb_cache_select' => array(), - 'qb_cache_from' => array(), - 'qb_cache_join' => array(), - 'qb_cache_where' => array(), - 'qb_cache_groupby' => array(), - 'qb_cache_having' => array(), - 'qb_cache_orderby' => array(), - 'qb_cache_set' => array(), - 'qb_cache_exists' => array(), - 'qb_cache_no_escape' => array() + 'qb_cache_select' => array(), + 'qb_cache_from' => array(), + 'qb_cache_join' => array(), + 'qb_cache_aliased_tables' => array(), + 'qb_cache_where' => array(), + 'qb_cache_groupby' => array(), + 'qb_cache_having' => array(), + 'qb_cache_orderby' => array(), + 'qb_cache_set' => array(), + 'qb_cache_exists' => array(), + 'qb_cache_no_escape' => array() )); return $this; @@ -2676,13 +2689,6 @@ abstract class CI_DB_query_builder extends CI_DB_driver { $this->qb_no_escape = $qb_no_escape; } } - - // If we are "protecting identifiers" we need to examine the "from" - // portion of the query to determine if there are any aliases - if ($this->_protect_identifiers === TRUE && count($this->qb_cache_from) > 0) - { - $this->_track_aliases($this->qb_from); - } } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 8d4af96a727140d49ffdb0ca05d2d154f3278e22 Mon Sep 17 00:00:00 2001 From: tianhe1986 Date: Tue, 17 Jan 2017 18:36:14 +0800 Subject: 1 Keep just 'list'. 2 Using strict mode with in_array(). 3 Do not re-align. Signed-off-by: tianhe1986 --- system/database/DB_query_builder.php | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/system/database/DB_query_builder.php b/system/database/DB_query_builder.php index 407b0d5d8..395f7c19b 100644 --- a/system/database/DB_query_builder.php +++ b/system/database/DB_query_builder.php @@ -215,7 +215,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver { protected $qb_cache_join = array(); /** - * QB Cache aliased tables list data + * QB Cache aliased tables list * * @var array */ @@ -2288,10 +2288,10 @@ abstract class CI_DB_query_builder extends CI_DB_driver { $table = trim(strrchr($table, ' ')); // Store the alias, if it doesn't already exist - if ( ! in_array($table, $this->qb_aliased_tables)) + if ( ! in_array($table, $this->qb_aliased_tables, TRUE)) { $this->qb_aliased_tables[] = $table; - if ($this->qb_caching === TRUE && ! in_array($table, $this->qb_cache_aliased_tables)) + if ($this->qb_caching === TRUE && ! in_array($table, $this->qb_cache_aliased_tables, TRUE)) { $this->qb_cache_aliased_tables[] = $table; $this->qb_cache_exists[] = 'aliased_tables'; @@ -2628,17 +2628,17 @@ abstract class CI_DB_query_builder extends CI_DB_driver { public function flush_cache() { $this->_reset_run(array( - 'qb_cache_select' => array(), - 'qb_cache_from' => array(), - 'qb_cache_join' => array(), + 'qb_cache_select' => array(), + 'qb_cache_from' => array(), + 'qb_cache_join' => array(), + 'qb_cache_where' => array(), + 'qb_cache_groupby' => array(), + 'qb_cache_having' => array(), + 'qb_cache_orderby' => array(), + 'qb_cache_set' => array(), + 'qb_cache_exists' => array(), + 'qb_cache_no_escape' => array(), 'qb_cache_aliased_tables' => array(), - 'qb_cache_where' => array(), - 'qb_cache_groupby' => array(), - 'qb_cache_having' => array(), - 'qb_cache_orderby' => array(), - 'qb_cache_set' => array(), - 'qb_cache_exists' => array(), - 'qb_cache_no_escape' => array() )); return $this; -- cgit v1.2.3-24-g4f1b From b044cc3aa55de4c54f6c28b0ad90f4a8534b5c72 Mon Sep 17 00:00:00 2001 From: tianhe1986 Date: Tue, 17 Jan 2017 18:38:23 +0800 Subject: Format fix。 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: tianhe1986 --- system/database/DB_query_builder.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/system/database/DB_query_builder.php b/system/database/DB_query_builder.php index 395f7c19b..09a4228bf 100644 --- a/system/database/DB_query_builder.php +++ b/system/database/DB_query_builder.php @@ -2630,7 +2630,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver { $this->_reset_run(array( 'qb_cache_select' => array(), 'qb_cache_from' => array(), - 'qb_cache_join' => array(), + 'qb_cache_join' => array(), 'qb_cache_where' => array(), 'qb_cache_groupby' => array(), 'qb_cache_having' => array(), @@ -2638,7 +2638,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver { 'qb_cache_set' => array(), 'qb_cache_exists' => array(), 'qb_cache_no_escape' => array(), - 'qb_cache_aliased_tables' => array(), + 'qb_cache_aliased_tables' => array() )); return $this; -- cgit v1.2.3-24-g4f1b