Skip to content

Commit 8456be6

Browse files
dev
1 parent 2a5efe0 commit 8456be6

File tree

1 file changed

+26
-8
lines changed

1 file changed

+26
-8
lines changed

src/console/controllers/SkeeksSuppliersController.php

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,23 @@ public function options($actionID)
6666
]);
6767
}
6868

69+
private $_base_memory_usage = 0;
70+
71+
/**
72+
* @return string
73+
*/
74+
private function _memoryUsage()
75+
{
76+
return \Yii::$app->formatter->asShortSize(memory_get_usage() - $this->_base_memory_usage);
77+
}
78+
6979
/**
7080
* @return false|void
7181
*/
7282
public function init()
7383
{
84+
$this->_base_memory_usage = memory_get_usage();
85+
7486
if (!isset(\Yii::$app->skeeksSuppliersApi)) {
7587
throw new Exception("Компонент skeeksSuppliersApi не подключен");
7688
}
@@ -118,7 +130,7 @@ public function actionUpdateCountries()
118130
{
119131
$response = \Yii::$app->skeeksSuppliersApi->methodCountries();
120132

121-
$this->stdout("Обновление стран [{$response->time} сек]", Console::BG_BLUE);
133+
$this->stdout("Обновление стран [{$response->time} сек] [{$this->_memoryUsage()}]", Console::BG_BLUE);
122134
$this->stdout("\n");
123135

124136
$updated = 0;
@@ -193,7 +205,7 @@ public function actionUpdateMeasures()
193205
{
194206
$response = \Yii::$app->skeeksSuppliersApi->methodMeasures();
195207

196-
$this->stdout("Обновление едениц измерения [{$response->time} сек]", Console::BG_BLUE);
208+
$this->stdout("Обновление едениц измерения [{$response->time} сек] [{$this->_memoryUsage()}]", Console::BG_BLUE);
197209
$this->stdout("\n");
198210

199211
$updated = 0;
@@ -250,7 +262,7 @@ public function actionUpdateCategories($page = 1)
250262
'page' => $page
251263
]);
252264

253-
$this->stdout("Обновление категорий, страница {$page} [{$response->time} сек]", Console::BG_BLUE);
265+
$this->stdout("Обновление категорий, страница {$page} [{$response->time} сек] [{$this->_memoryUsage()}]", Console::BG_BLUE);
254266
$this->stdout("\n");
255267

256268
$total = $response->headers->get("x-pagination-total-count");
@@ -301,6 +313,7 @@ public function actionUpdateCategories($page = 1)
301313
}
302314

303315
if ($page < $pageCount) {
316+
unset($response);
304317
$this->actionUpdateCategories($page + 1);
305318
}
306319
}
@@ -315,7 +328,7 @@ public function actionUpdateProperties($page = 1)
315328
'page' => $page
316329
]);
317330

318-
$this->stdout("Обновление характеристик, страница {$page} [{$response->time} сек]", Console::BG_BLUE);
331+
$this->stdout("Обновление характеристик, страница {$page} [{$response->time} сек] [{$this->_memoryUsage()}]", Console::BG_BLUE);
319332
$this->stdout("\n");
320333

321334
$total = $response->headers->get("x-pagination-total-count");
@@ -364,6 +377,7 @@ public function actionUpdateProperties($page = 1)
364377
}
365378

366379
if ($page < $pageCount) {
380+
unset($response);
367381
$this->actionUpdateProperties($page + 1);
368382
}
369383
}
@@ -378,7 +392,7 @@ public function actionUpdateBrands($page = 1)
378392
'page' => $page
379393
]);
380394

381-
$this->stdout("Обновление брендов, страница {$page} [{$response->time} сек]", Console::BG_BLUE);
395+
$this->stdout("Обновление брендов, страница {$page} [{$response->time} сек] [{$this->_memoryUsage()}]", Console::BG_BLUE);
382396
$this->stdout("\n");
383397

384398
$total = $response->headers->get("x-pagination-total-count");
@@ -427,6 +441,7 @@ public function actionUpdateBrands($page = 1)
427441
}
428442

429443
if ($page < $pageCount) {
444+
unset($response);
430445
$this->actionUpdateBrands($page + 1);
431446
}
432447
}
@@ -442,7 +457,7 @@ public function actionUpdateCollections($page = 1)
442457
'page' => $page
443458
]);
444459

445-
$this->stdout("Обновление коллекций, страница {$page} [{$response->time} сек]", Console::BG_BLUE);
460+
$this->stdout("Обновление коллекций, страница {$page} [{$response->time} сек] [{$this->_memoryUsage()}]", Console::BG_BLUE);
446461
$this->stdout("\n");
447462

448463
$total = $response->headers->get("x-pagination-total-count");
@@ -491,6 +506,7 @@ public function actionUpdateCollections($page = 1)
491506
}
492507

493508
if ($page < $pageCount) {
509+
unset($response);
494510
$this->actionUpdateCollections($page + 1);
495511
}
496512
}
@@ -505,7 +521,7 @@ public function actionUpdateStores($page = 1)
505521
'page' => $page
506522
]);
507523

508-
$this->stdout("Обновление складов, страница {$page} [{$response->time} сек]", Console::BG_BLUE);
524+
$this->stdout("Обновление складов, страница {$page} [{$response->time} сек] [{$this->_memoryUsage()}]", Console::BG_BLUE);
509525
$this->stdout("\n");
510526

511527
$total = $response->headers->get("x-pagination-total-count");
@@ -555,6 +571,7 @@ public function actionUpdateStores($page = 1)
555571
}
556572

557573
if ($page < $pageCount) {
574+
unset($response);
558575
$this->actionUpdateStores($page + 1);
559576
}
560577
}
@@ -590,7 +607,7 @@ public function actionUpdateProducts($is_new = 1, $page = 1)
590607

591608
$response = \Yii::$app->skeeksSuppliersApi->methodProducts($apiQuery);
592609

593-
$this->stdout("Обновление товаров, страница {$page} [{$response->time} сек]", Console::BG_BLUE);
610+
$this->stdout("Обновление товаров, страница {$page} [{$response->time} сек] [{$this->_memoryUsage()}]", Console::BG_BLUE);
594611
$this->stdout("\n");
595612

596613
$total = $response->headers->get("x-pagination-total-count");
@@ -643,6 +660,7 @@ public function actionUpdateProducts($is_new = 1, $page = 1)
643660
}
644661

645662
if ($page < $pageCount) {
663+
unset($response);
646664
$this->actionUpdateProducts($is_new, $page + 1);
647665
}
648666
}

0 commit comments

Comments
 (0)