Przeglądaj źródła

fixed performance in P5Menu

Piotr Labudda 8 lat temu
rodzic
commit
225c3baa5c
1 zmienionych plików z 20 dodań i 2 usunięć
  1. 20 2
      SE/se-lib/Route/P5Menu.php

+ 20 - 2
SE/se-lib/Route/P5Menu.php

@@ -49,6 +49,12 @@ class Route_P5Menu extends RouteBase {
 		$bookmarks = UserBookmarks::getInstance()->getBookmarks();
 		$makeShortLabel = [ $this, 'getRawLabel' ];
 
+		$sqlIds = implode(", ", array_keys($listObjects));
+		$cacheZasobInfo = DB::getPDO()->fetchAllByKey("
+			select `ID`, `DESC`, `DESC_PL`, `OPIS`
+			from CRM_LISTA_ZASOBOW
+			where ID in ({$sqlIds})
+		", $key = 'ID');
 		return [
 			'type' => 'success',
 			'msg' => "OK",
@@ -56,13 +62,25 @@ class Route_P5Menu extends RouteBase {
 				'version' => $this->getVersion(),
 
 				'objects' => array_values( array_filter(
-					array_map(function ($acl, $idZasob) use ($makeShortLabel) {
+					array_map(function ($acl, $idZasob) use ($makeShortLabel, $cacheZasobInfo) {
 						if (!$acl) return [
 							'id' => $idZasob,
 							'TODO' => 'TODO'
 						];
 
-						$zasobObj = ProcesHelper::getZasobTableInfo($acl->getID());
+						// $zasobObj = ProcesHelper::getZasobTableInfo($acl->getID());
+						// $zasobObj = (object)DB::getPDO()->fetchFirst("
+						// 	select `ID`, `DESC`, `DESC_PL`, `OPIS`
+						// 	from CRM_LISTA_ZASOBOW
+						// 	where ID = :id
+						// ", [ ':id' => $acl->getID() ]);
+						// if ((int)$idZasob !== (int)$acl->getID()) throw new Exception("BUG idZasob !== Acl->getID() : ({$idZasob}) !== (".$acl->getID().")");
+						if (!array_key_exists($acl->getID(), $cacheZasobInfo)) return [
+							'id' => $idZasob,
+							'TODO' => "Zasób '{$idZasob}' nie istnieje w bazie"
+						];
+
+						$zasobObj = (object)$cacheZasobInfo[$acl->getID()];
 						return [
 							'id' => $acl->getID(),
 							'namespace' => $acl->getNamespace(),