From 849151949a9f3760e7fff69bd8722503310e225e Mon Sep 17 00:00:00 2001 From: Simon Leary Date: Mon, 7 Apr 2025 11:00:05 -0400 Subject: [PATCH 1/4] cache user/group exists --- resources/lib/UnityGroup.php | 6 +++++- resources/lib/UnityUser.php | 8 +++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/resources/lib/UnityGroup.php b/resources/lib/UnityGroup.php index d1616225..973e5079 100644 --- a/resources/lib/UnityGroup.php +++ b/resources/lib/UnityGroup.php @@ -62,8 +62,12 @@ public function getPIUID() * * @return bool true if yes, false if no */ - public function exists() + public function exists($ignorecache = false) { + if (!$ignorecache) { + $cached_pi_groups = $this->REDIS->getCache("sorted_pi_groups", ""); + return in_array($this->getPIUID(), $cached_pi_groups); + } return $this->getLDAPPiGroup()->exists(); } diff --git a/resources/lib/UnityUser.php b/resources/lib/UnityUser.php index 4f88eac6..f0c6da4d 100644 --- a/resources/lib/UnityUser.php +++ b/resources/lib/UnityUser.php @@ -154,8 +154,14 @@ public function getLDAPGroup() return $this->LDAP->getGroupEntry($this->uid); } - public function exists() + public function exists($ignorecache = false) { + if (!$ignorecache) { + $cached_val = $this->REDIS->getCache($this->uid, "cn"); + if (!is_null($cached_val)) { + return true; + } + } return $this->getLDAPUser()->exists() && $this->getLDAPGroup()->exists(); } From d76251ab5c1289f4328f6a231285ad05b3d8c4fc Mon Sep 17 00:00:00 2001 From: Simon Leary Date: Mon, 7 Apr 2025 12:24:54 -0400 Subject: [PATCH 2/4] handle null edge case --- resources/lib/UnityGroup.php | 4 +++- resources/lib/UnityUser.php | 6 +++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/resources/lib/UnityGroup.php b/resources/lib/UnityGroup.php index 973e5079..b6043af0 100644 --- a/resources/lib/UnityGroup.php +++ b/resources/lib/UnityGroup.php @@ -66,7 +66,9 @@ public function exists($ignorecache = false) { if (!$ignorecache) { $cached_pi_groups = $this->REDIS->getCache("sorted_pi_groups", ""); - return in_array($this->getPIUID(), $cached_pi_groups); + if (!is_null($cached_pi_groups)) { + return in_array($this->getPIUID(), $cached_pi_groups); + } } return $this->getLDAPPiGroup()->exists(); } diff --git a/resources/lib/UnityUser.php b/resources/lib/UnityUser.php index f0c6da4d..367950d7 100644 --- a/resources/lib/UnityUser.php +++ b/resources/lib/UnityUser.php @@ -157,9 +157,9 @@ public function getLDAPGroup() public function exists($ignorecache = false) { if (!$ignorecache) { - $cached_val = $this->REDIS->getCache($this->uid, "cn"); - if (!is_null($cached_val)) { - return true; + $cached_users = $this->REDIS->getCache("sorted_users", ""); + if (!is_null($cached_users)) { + return in_array($this->getPIUID(), $cached_users); } } return $this->getLDAPUser()->exists() && $this->getLDAPGroup()->exists(); From fe080d271f96e8975722f4edfa5735673db5f24c Mon Sep 17 00:00:00 2001 From: Simon Leary Date: Mon, 7 Apr 2025 12:25:49 -0400 Subject: [PATCH 3/4] type annotations --- resources/lib/UnityGroup.php | 2 +- resources/lib/UnityUser.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/resources/lib/UnityGroup.php b/resources/lib/UnityGroup.php index b6043af0..be94bb4e 100644 --- a/resources/lib/UnityGroup.php +++ b/resources/lib/UnityGroup.php @@ -62,7 +62,7 @@ public function getPIUID() * * @return bool true if yes, false if no */ - public function exists($ignorecache = false) + public function exists(bool $ignorecache = false): bool { if (!$ignorecache) { $cached_pi_groups = $this->REDIS->getCache("sorted_pi_groups", ""); diff --git a/resources/lib/UnityUser.php b/resources/lib/UnityUser.php index 367950d7..9216227e 100644 --- a/resources/lib/UnityUser.php +++ b/resources/lib/UnityUser.php @@ -154,7 +154,7 @@ public function getLDAPGroup() return $this->LDAP->getGroupEntry($this->uid); } - public function exists($ignorecache = false) + public function exists(bool $ignorecache = false): bool { if (!$ignorecache) { $cached_users = $this->REDIS->getCache("sorted_users", ""); From 6c6e1796dd1dac19463065f869bfc14463db888e Mon Sep 17 00:00:00 2001 From: Simon Leary Date: Mon, 7 Apr 2025 12:26:51 -0400 Subject: [PATCH 4/4] oops --- resources/lib/UnityUser.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/lib/UnityUser.php b/resources/lib/UnityUser.php index 9216227e..3df33d6f 100644 --- a/resources/lib/UnityUser.php +++ b/resources/lib/UnityUser.php @@ -159,7 +159,7 @@ public function exists(bool $ignorecache = false): bool if (!$ignorecache) { $cached_users = $this->REDIS->getCache("sorted_users", ""); if (!is_null($cached_users)) { - return in_array($this->getPIUID(), $cached_users); + return in_array($this->uid, $cached_users); } } return $this->getLDAPUser()->exists() && $this->getLDAPGroup()->exists();