[icinga-checkins] icinga.org: icingaweb2/master: Repository: Fix column caches

git at icinga.org git at icinga.org
Thu Aug 18 15:30:55 CEST 2016


Module: icingaweb2
Branch: master
Commit: bd4f21df1190833d01c1e956f4b34c7f8462e5f8
URL:    https://git.icinga.org/?p=icingaweb2.git;a=commit;h=bd4f21df1190833d01c1e956f4b34c7f8462e5f8

Author: Johannes Meyer <johannes.meyer at netways.de>
Date:   Thu Aug 18 15:30:47 2016 +0200

Repository: Fix column caches


---

 library/Icinga/Repository/Repository.php |   86 +++++++++++++++++++++++++++---
 1 file changed, 78 insertions(+), 8 deletions(-)

diff --git a/library/Icinga/Repository/Repository.php b/library/Icinga/Repository/Repository.php
index 2fd8ace..a211a25 100644
--- a/library/Icinga/Repository/Repository.php
+++ b/library/Icinga/Repository/Repository.php
@@ -91,6 +91,13 @@ abstract class Repository implements Selectable
     protected $blacklistedQueryColumns;
 
     /**
+     * Whether the blacklisted query columns are in the legacy format
+     *
+     * @var bool
+     */
+    protected $legacyBlacklistedQueryColumns;
+
+    /**
      * The filter columns being provided
      *
      * This may be intialized by concrete repository implementations, in the following format
@@ -106,6 +113,13 @@ abstract class Repository implements Selectable
     protected $filterColumns;
 
     /**
+     * Whether the provided filter columns are in the legacy format
+     *
+     * @var bool
+     */
+    protected $legacyFilterColumns;
+
+    /**
      * The search columns (or aliases) being provided
      *
      * @var array   An array of strings
@@ -113,6 +127,13 @@ abstract class Repository implements Selectable
     protected $searchColumns;
 
     /**
+     * Whether the provided search columns are in the legacy format
+     *
+     * @var bool
+     */
+    protected $legacySearchColumns;
+
+    /**
      * The sort rules to be applied on a query
      *
      * This may be initialized by concrete repository implementations, in the following format
@@ -141,6 +162,13 @@ abstract class Repository implements Selectable
     protected $sortRules;
 
     /**
+     * Whether the provided sort rules are in the legacy format
+     *
+     * @var bool
+     */
+    protected $legacySortRules;
+
+    /**
      * The value conversion rules to apply on a query or statement
      *
      * This may be initialized by concrete repository implementations and describes for which aliases or column
@@ -330,10 +358,21 @@ abstract class Repository implements Selectable
     public function getBlacklistedQueryColumns($table = null)
     {
         if ($this->blacklistedQueryColumns === null) {
-            $this->blacklistedQueryColumns = $this->initializeBlacklistedQueryColumns($table);
+            $this->legacyBlacklistedQueryColumns = false;
+
+            $blacklistedQueryColumns = $this->initializeBlacklistedQueryColumns($table);
+            if (is_int(key($blacklistedQueryColumns))) {
+                $this->blacklistedQueryColumns[$table] = $blacklistedQueryColumns;
+            } else {
+                $this->blacklistedQueryColumns = $blacklistedQueryColumns;
+            }
+        } elseif ($this->legacyBlacklistedQueryColumns === null) {
+            $this->legacyBlacklistedQueryColumns = is_int(key($this->blacklistedQueryColumns));
         }
 
-        return $this->blacklistedQueryColumns;
+        return $this->legacyBlacklistedQueryColumns
+            ? $this->blacklistedQueryColumns
+            : $this->blacklistedQueryColumns[$table];
     }
 
     /**
@@ -362,10 +401,21 @@ abstract class Repository implements Selectable
     public function getFilterColumns($table = null)
     {
         if ($this->filterColumns === null) {
-            $this->filterColumns = $this->initializeFilterColumns($table);
+            $this->legacyFilterColumns = false;
+
+            $filterColumns = $this->initializeFilterColumns($table);
+            $foundTables = array_intersect_key($this->getQueryColumns(), $filterColumns);
+            if (empty($foundTables)) {
+                $this->filterColumns[$table] = $filterColumns;
+            } else {
+                $this->filterColumns = $filterColumns;
+            }
+        } elseif ($this->legacyFilterColumns === null) {
+            $foundTables = array_intersect_key($this->getQueryColumns(), $this->filterColumns);
+            $this->legacyFilterColumns = empty($foundTables);
         }
 
-        return $this->filterColumns;
+        return $this->legacyFilterColumns ? $this->filterColumns : $this->filterColumns[$table];
     }
 
     /**
@@ -394,10 +444,19 @@ abstract class Repository implements Selectable
     public function getSearchColumns($table = null)
     {
         if ($this->searchColumns === null) {
-            $this->searchColumns = $this->initializeSearchColumns($table);
+            $this->legacySearchColumns = false;
+
+            $searchColumns = $this->initializeSearchColumns($table);
+            if (is_int(key($searchColumns))) {
+                $this->searchColumns[$table] = $searchColumns;
+            } else {
+                $this->searchColumns = $searchColumns;
+            }
+        } elseif ($this->legacySearchColumns === null) {
+            $this->legacySearchColumns = is_int(key($this->searchColumns));
         }
 
-        return $this->searchColumns;
+        return $this->legacySearchColumns ? $this->searchColumns : $this->searchColumns[$table];
     }
 
     /**
@@ -426,10 +485,21 @@ abstract class Repository implements Selectable
     public function getSortRules($table = null)
     {
         if ($this->sortRules === null) {
-            $this->sortRules = $this->initializeSortRules($table);
+            $this->legacySortRules = false;
+
+            $sortRules = $this->initializeSortRules($table);
+            $foundTables = array_intersect_key($this->getQueryColumns(), $sortRules);
+            if (empty($foundTables)) {
+                $this->sortRules[$table] = $sortRules;
+            } else {
+                $this->sortRules = $sortRules;
+            }
+        } elseif ($this->legacySortRules === null) {
+            $foundTables = array_intersect_key($this->getQueryColumns(), $this->sortRules);
+            $this->legacyFilterColumns = empty($foundTables);
         }
 
-        return $this->sortRules;
+        return $this->legacySortRules ? $this->sortRules : $this->sortRules[$table];
     }
 
     /**



More information about the icinga-checkins mailing list