| Conditions | 4 |
| Paths | 4 |
| Total Lines | 51 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 19 | public function run($request) |
||
| 20 | { |
||
| 21 | ini_set('max_execution_time', 3000); |
||
| 22 | $tables = DB::query('SHOW TABLE STATUS WHERE ENGINE <> \'InnoDB\''); |
||
| 23 | foreach ($tables as $table) { |
||
| 24 | $table = $table["Name"]; |
||
| 25 | DB::alteration_message("Updating $table to innoDB", "created"); |
||
| 26 | $this->flushNow(); |
||
| 27 | $indexRows = DB::query("SHOW INDEX FROM \"$table\" WHERE Index_type = 'FULLTEXT'"); |
||
| 28 | unset($done); |
||
| 29 | $done = array(); |
||
| 30 | foreach ($indexRows as $indexRow) { |
||
| 31 | $key = $indexRow["Key_name"]; |
||
| 32 | if (!isset($done[$key])) { |
||
| 33 | DB::alteration_message("Deleting INDEX $key in $table (FullText Index)", "deleted"); |
||
| 34 | $this->flushNow(); |
||
| 35 | DB::query("ALTER TABLE \"$table\" DROP INDEX $key;"); |
||
| 36 | $done[$key] = $key; |
||
| 37 | } |
||
| 38 | } |
||
| 39 | $sql = "ALTER TABLE \"$table\" ENGINE=INNODB"; |
||
| 40 | DB::query($sql); |
||
| 41 | } |
||
| 42 | //$rows = DB::query("SHOW GLOBAL STATUS LIKE 'Innodb_page_size'"); |
||
| 43 | $currentInnoDBSetting = DB::query("SELECT @@innodb_buffer_pool_size as V;")->Value(); |
||
| 44 | $innoDBBufferUsed = DB::query(" |
||
| 45 | |||
| 46 | SELECT (PagesData*PageSize)/POWER(1024,3) DataGB FROM |
||
| 47 | (SELECT variable_value PagesData |
||
| 48 | FROM information_schema.global_status |
||
| 49 | WHERE variable_name='Innodb_buffer_pool_pages_data') A, |
||
| 50 | (SELECT variable_value PageSize |
||
| 51 | FROM information_schema.global_status |
||
| 52 | WHERE variable_name='Innodb_page_size') B; |
||
| 53 | |||
| 54 | ")->value(); |
||
| 55 | $innoBDBufferRecommended = DB::query( |
||
| 56 | " |
||
| 57 | SELECT CEILING(Total_InnoDB_Bytes*1.6/POWER(1024,3)) RIBPS FROM |
||
| 58 | (SELECT SUM(data_length+index_length) Total_InnoDB_Bytes |
||
| 59 | FROM information_schema.tables WHERE engine='InnoDB') A; |
||
| 60 | " |
||
| 61 | )->value(); |
||
| 62 | DB::alteration_message("<hr /><hr /><hr /><hr /><hr /><hr /><hr />COMPLETED |
||
| 63 | <br /> |
||
| 64 | Please check your MYSQL innodb_buffer_pool_size setting. |
||
| 65 | It is currently using ".round($innoDBBufferUsed, 3)."G, |
||
| 66 | but it should be set to ".round($innoBDBufferRecommended, 3)."G. |
||
| 67 | The current setting is: ".round($currentInnoDBSetting / (1042 * 1024* 1024))."G |
||
| 68 | <hr /><hr /><hr /><hr /><hr /><hr /><hr />"); |
||
| 69 | } |
||
| 70 | |||
| 82 |
If you suppress an error, we recommend checking for the error condition explicitly: