From 923e4bc2a8d189010afd3a7af6606da8dcf3f2f7 Mon Sep 17 00:00:00 2001
From: Thomas Hackl <hackl@data-quest.de>
Date: Mon, 27 Sep 2021 10:56:04 +0200
Subject: [PATCH] check already queried database fields and don't query again,
 re #175

---
 lib/classes/admission/UserFilterField.class.php | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/lib/classes/admission/UserFilterField.class.php b/lib/classes/admission/UserFilterField.class.php
index 72a09178537..36ed57cea30 100644
--- a/lib/classes/admission/UserFilterField.class.php
+++ b/lib/classes/admission/UserFilterField.class.php
@@ -313,8 +313,13 @@ class UserFilterField
         $parameters = [$userId];
         // Additional requirements given...
         if (is_array($additional)) {
+
+            // Don't use the same database field twice as this can only get ugly.
+            $usedFields = [$this->userDataDbField];
+
             foreach ($additional as $a_condition) {
-                if ($a_condition->id != $this->id && $this->userDataDbTable == $a_condition->userDataDbTable) {
+                if ($a_condition->id != $this->id && $this->userDataDbTable == $a_condition->userDataDbTable &&
+                        !in_array($a_condition->userDataDbField, $usedFields)) {
                     $query .= " AND `" . $a_condition->userDataDbField . "` " . $a_condition->compareOperator . "?";
                     $parameters[] = $a_condition->value;
                 }
-- 
GitLab