@@ -41,8 +41,10 @@ class StorageGlobal {
4141 /** @var IDBConnection */
4242 private $ connection ;
4343
44- /** @var array[] */
44+ /** @var array<string, array> */
4545 private $ cache = [];
46+ /** @var array<int, array> */
47+ private $ numericIdCache = [];
4648
4749 public function __construct (IDBConnection $ connection ) {
4850 $ this ->connection = $ connection ;
@@ -68,7 +70,7 @@ public function loadForStorageIds(array $storageIds) {
6870 * @param string $storageId
6971 * @return array|null
7072 */
71- public function getStorageInfo ($ storageId ) {
73+ public function getStorageInfo (string $ storageId ): ? array {
7274 if (!isset ($ this ->cache [$ storageId ])) {
7375 $ builder = $ this ->connection ->getQueryBuilder ();
7476 $ query = $ builder ->select (['id ' , 'numeric_id ' , 'available ' , 'last_checked ' ])
@@ -81,9 +83,33 @@ public function getStorageInfo($storageId) {
8183
8284 if ($ row ) {
8385 $ this ->cache [$ storageId ] = $ row ;
86+ $ this ->numericIdCache [(int )$ row ['numeric_id ' ]] = $ row ;
8487 }
8588 }
86- return isset ($ this ->cache [$ storageId ]) ? $ this ->cache [$ storageId ] : null ;
89+ return $ this ->cache [$ storageId ] ?? null ;
90+ }
91+
92+ /**
93+ * @param int $numericId
94+ * @return array|null
95+ */
96+ public function getStorageInfoByNumericId (int $ numericId ): ?array {
97+ if (!isset ($ this ->numericIdCache [$ numericId ])) {
98+ $ builder = $ this ->connection ->getQueryBuilder ();
99+ $ query = $ builder ->select (['id ' , 'numeric_id ' , 'available ' , 'last_checked ' ])
100+ ->from ('storages ' )
101+ ->where ($ builder ->expr ()->eq ('numeric_id ' , $ builder ->createNamedParameter ($ numericId )));
102+
103+ $ result = $ query ->execute ();
104+ $ row = $ result ->fetch ();
105+ $ result ->closeCursor ();
106+
107+ if ($ row ) {
108+ $ this ->numericIdCache [$ numericId ] = $ row ;
109+ $ this ->cache [$ row ['id ' ]] = $ row ;
110+ }
111+ }
112+ return $ this ->numericIdCache [$ numericId ] ?? null ;
87113 }
88114
89115 public function clearCache () {
0 commit comments