Add cache for user ranks
authorMarcel Werk <burntime@woltlab.com>
Sun, 4 Feb 2024 16:29:44 +0000 (17:29 +0100)
committerMarcel Werk <burntime@woltlab.com>
Sun, 4 Feb 2024 16:29:44 +0000 (17:29 +0100)
wcfsetup/install/files/lib/data/user/rank/UserRankEditor.class.php
wcfsetup/install/files/lib/system/cache/builder/UserRankCacheBuilder.class.php [new file with mode: 0644]

index af2bcfaff300b675d0c3605dd855c7608f1ae2dc..e57f20efeb5409d8f97e21de7984ae0364b44f75 100644 (file)
@@ -4,7 +4,7 @@ namespace wcf\data\user\rank;
 
 use wcf\data\DatabaseObjectEditor;
 use wcf\data\IEditableCachedObject;
-use wcf\system\user\storage\UserStorageHandler;
+use wcf\system\cache\builder\UserRankCacheBuilder;
 
 /**
  * Provides functions to edit user ranks.
@@ -29,6 +29,6 @@ class UserRankEditor extends DatabaseObjectEditor implements IEditableCachedObje
      */
     public static function resetCache()
     {
-        UserStorageHandler::getInstance()->resetAll('userRank');
+        UserRankCacheBuilder::getInstance()->reset();
     }
 }
diff --git a/wcfsetup/install/files/lib/system/cache/builder/UserRankCacheBuilder.class.php b/wcfsetup/install/files/lib/system/cache/builder/UserRankCacheBuilder.class.php
new file mode 100644 (file)
index 0000000..878a834
--- /dev/null
@@ -0,0 +1,33 @@
+<?php
+
+namespace wcf\system\cache\builder;
+
+use wcf\data\user\rank\UserRank;
+use wcf\data\user\rank\UserRankList;
+
+/**
+ * Caches the list of user ranks.
+ *
+ * @author      Marcel Werk
+ * @copyright   2001-2024 WoltLab GmbH
+ * @license     GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @since       6.1
+ */
+final class UserRankCacheBuilder extends AbstractCacheBuilder
+{
+    /**
+     * @inheritDoc
+     */
+    public function rebuild(array $parameters)
+    {
+        $list = new UserRankList();
+        $list->readObjects();
+
+        return $list->getObjects();
+    }
+
+    public function getRank(int $rankID): ?UserRank
+    {
+        return $this->getData()[$rankID] ?? null;
+    }
+}