浏览代码

Patch contacts calling multiple schemas (#6826)

* improve performance for contacts app_defaults

* add app_name and app_uuid as constants in class

* performance boost by removing scanning app_defaults twice

* Update app_defaults.php

* Update schema.php

---------

Co-authored-by: FusionPBX <[email protected]>
frytimo 1 年之前
父节点
当前提交
72dd61d59a
共有 1 个文件被更改,包括 10 次插入27 次删除
  1. 10 27
      resources/classes/schema.php

+ 10 - 27
resources/classes/schema.php

@@ -523,22 +523,9 @@ if (!class_exists('schema')) {
 						//check if table exists
 							// SELECT TABLE_NAME FROM ALL_TABLES
 
-				//get the $apps array from the installed apps from the core and mod directories
-					$config_list = glob($_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . "/*/*/app_config.php");
-					$x=0;
-					foreach ($config_list as &$config_path) {
-						try {
-							include($config_path);
-						}
-						catch (Exception $e) {
-						    //echo 'Caught exception: ',  $e->getMessage(), "\n";
-						}
-						$x++;
-					}
-
 				//update the app db array add exists true or false
 					$sql = '';
-					foreach ($apps as $x => &$app) {
+					foreach ($this->apps as $x => &$app) {
 						if (isset($app['db'])) foreach ($app['db'] as $y => &$row) {
 							if (isset($row['table']['name'])) {
 								if (is_array($row['table']['name'])) {
@@ -598,10 +585,9 @@ if (!class_exists('schema')) {
 
 				//prepare the variables
 					$sql_update = '';
-					$var_uuid = $_GET["id"] ?? '';
 
 				//add missing tables and fields
-					foreach ($apps as $x => &$app) {
+					foreach ($this->apps as $x => &$app) {
 						if (isset($app['db'])) foreach ($app['db'] as $y => &$row) {
 							if (is_array($row['table']['name'])) {
 								$table_name = $row['table']['name']['text'];
@@ -623,7 +609,7 @@ if (!class_exists('schema')) {
 									}
 									else {
 										$row['exists'] = "false";
-										$sql_update .= $this->db_create_table($apps, $db_type, $row['table']['name']['text']);
+										$sql_update .= $this->db_create_table($this->apps, $db_type, $row['table']['name']['text']);
 									}
 								}
 							}
@@ -649,7 +635,7 @@ if (!class_exists('schema')) {
 													if (is_array($field['name'])) {
 														$field_name = $field['name']['text'];
 														if (!$this->db_column_exists ($db_type, $db_name, $table_name, $field_name)) {
-															$field['exists'] == "false";
+															$field['exists'] = "false";
 														}
 													}
 													else {
@@ -734,19 +720,18 @@ if (!class_exists('schema')) {
 
 											}
 										}
-										unset($column_array);
 									}
 								}
 								else {
 									//create table
 										if (!is_array($row['table']['name'])) {
-											$sql_update .= $this->db_create_table($apps, $db_type, $row['table']['name']);
+											$sql_update .= $this->db_create_table($this->apps, $db_type, $row['table']['name']);
 										}
 								}
 						}
 					}
 				//rebuild and populate the table
-					foreach ($apps as $x => &$app) {
+					foreach ($this->apps as $x => &$app) {
 						if (isset($app['db'])) foreach ($app['db'] as $y => &$row) {
 							if (is_array($row['table']['name'])) {
 								$table_name = $row['table']['name']['text'];
@@ -761,9 +746,9 @@ if (!class_exists('schema')) {
 									//rename the table
 										$sql_update .= "ALTER TABLE ".$table_name." RENAME TO tmp_".$table_name.";\n";
 									//create the table
-										$sql_update .= $this->db_create_table($apps, $db_type, $table_name);
+										$sql_update .= $this->db_create_table($this->apps, $db_type, $table_name);
 									//insert the data into the new table
-										$sql_update .= $this->db_insert_into($apps, $db_type, $table_name);
+										$sql_update .= $this->db_insert_into($this->apps, $db_type, $table_name);
 									//drop the old table
 										$sql_update .= "DROP TABLE tmp_".$table_name.";\n";
 									//commit the transaction
@@ -803,7 +788,7 @@ if (!class_exists('schema')) {
 							$response .= "<tr>\n";
 						//build the html while looping through the app db array
 							$sql = '';
-							foreach ($apps as &$app) {
+							foreach ($this->apps as &$app) {
 								if (isset($app['db'])) foreach ($app['db'] as $row) {
 									if (is_array($row['table']['name'])) {
 										$table_name = $row['table']['name']['text'];
@@ -858,7 +843,6 @@ if (!class_exists('schema')) {
 															$response .= "</tr>\n";
 														}
 													}
-													unset($column_array);
 													$response .= "	</table>\n";
 													$response .= "</td>\n";
 											}
@@ -871,7 +855,6 @@ if (!class_exists('schema')) {
 										$response .= "</tr>\n";
 								}
 							}
-							unset ($prep_statement);
 						//end the list of tables
 							$response .= "</table>\n";
 							$response .= "<br />\n";
@@ -904,7 +887,7 @@ if (!class_exists('schema')) {
 							}
 							//$this->db->commit();
 							$response .= "\n";
-							unset ($file_contents, $sql_update, $sql);
+							unset ($sql_update, $sql);
 						}
 
 				//handle response