Skip to content

Commit 4229aff

Browse files
Merge pull request #4 from devimteam/1.1.7
1.1.7
2 parents 8f9c7a0 + e7a9478 commit 4229aff

3 files changed

Lines changed: 67 additions & 13 deletions

File tree

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"license": "",
77
"authors": [],
88
"minimum-stability": "stable",
9+
"version": "1.1.7",
910
"require": {
1011
"php": ">=7",
1112
"silex/silex": "^2.0",

src/DataImporter.php

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
use Devim\Component\DataImporter\Exception\BadPersistsData;
88
use Devim\Component\DataImporter\Exception\EntityManagerIsClosed;
99
use Devim\Component\DataImporter\Exception\UnexpectedTypeException;
10+
use Devim\Component\DataImporter\ExceptionHandler\ImportExceptionHandlerInterface;
11+
use Devim\Component\DataImporter\ExceptionHandler\LogHandler;
1012
use Devim\Component\DataImporter\Filter\FilterInterface;
1113
use Devim\Component\DataImporter\Reader\ReaderInterface;
1214
use Devim\Component\DataImporter\Writer\WriterInterface;
13-
use Devim\Component\DataImporter\ExceptionHandler\ImportExceptionHandlerInterface;
14-
use Devim\Component\DataImporter\ExceptionHandler\LogHandler;
1515
use Psr\Log\LoggerInterface;
1616
use Psr\Log\NullLogger;
1717

@@ -139,15 +139,17 @@ public function process(ImportParameters $importParameters)
139139

140140
$this->doPrepare();
141141

142+
$time = microtime(true);
142143
$this->reader->beforeRead();
143-
144+
$importResult->addSelectTime(microtime(true) - $time);
144145
foreach ($this->reader->read() as $data) {
145146
try {
146147
if (!$this->filterData($data, $this->beforeConvertFilterQueue)) {
147148
continue;
148149
}
150+
$time = microtime(true);
149151
$convertedData = $this->convertData($data);
150-
152+
$importResult->addConvertTime(microtime(true) - $time);
151153
if (!$convertedData) {
152154
continue;
153155
}
@@ -156,21 +158,20 @@ public function process(ImportParameters $importParameters)
156158
continue;
157159
}
158160

161+
$time = microtime(true);
159162
$this->doWriteData($convertedData);
160-
163+
$importResult->addInsertTime(microtime(true) - $time);
161164
$importResult->incrementSuccessCount();
162-
}
163-
//Если EntityManager закрыт сделать ничего нельзя, выходим из программы
164-
catch (EntityManagerIsClosed $exception){
165+
} //Если EntityManager закрыт сделать ничего нельзя, выходим из программы
166+
catch (EntityManagerIsClosed $exception) {
165167
$this->exceptionHandler->handle($exception, $exception->getData());
166168

167169
throw $exception;
168-
}catch (BadPersistsData $persistsDataException){
170+
} catch (BadPersistsData $persistsDataException) {
169171
$importResult->addErrors($persistsDataException->getData());
170172

171173
$this->exceptionHandler->handle($persistsDataException, $persistsDataException->getData());
172-
}
173-
//Сталкивался с type error, когда в арчи кривые данные лежали при convertData
174+
} //Сталкивался с type error, когда в арчи кривые данные лежали при convertData
174175
catch (\Throwable $e) {
175176
$importResult->addErrors([$data]);
176177

@@ -182,11 +183,11 @@ public function process(ImportParameters $importParameters)
182183

183184
try {
184185
$this->doFinish();
185-
}catch (EntityManagerIsClosed $exception){
186+
} catch (EntityManagerIsClosed $exception) {
186187
$this->exceptionHandler->handle($exception, $exception->getData());
187188

188189
throw $exception;
189-
}catch (BadPersistsData $exception){
190+
} catch (BadPersistsData $exception) {
190191
$this->exceptionHandler->handle($exception, $exception->getData());
191192
$importResult->addErrors($exception->getData());
192193
}

src/ImportResult.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ class ImportResult
1616
*/
1717
private $errorData = [];
1818

19+
private $selectTime = [];
20+
21+
private $convertTime = [];
22+
23+
private $insertTime = [];
24+
1925
/**
2026
*
2127
* @return $this
@@ -56,4 +62,50 @@ public function getErrorData(): array
5662
{
5763
return $this->errorData;
5864
}
65+
66+
public function addSelectTime(float $time): self
67+
{
68+
$this->selectTime[] = $this;
69+
return $this;
70+
}
71+
72+
public function addConvertTime(float $time): self
73+
{
74+
$this->convertTime[] = $this;
75+
return $this;
76+
}
77+
78+
public function addInsertTime(float $time): self
79+
{
80+
$this->insertTime[] = $time;
81+
82+
return $this;
83+
}
84+
85+
public function getSelectTime(): float
86+
{
87+
if (!count($this->selectTime)) {
88+
return 0.0;
89+
}
90+
91+
return array_sum($this->selectTime) / count($this->selectTime);
92+
}
93+
94+
public function getConvertTime(): float
95+
{
96+
if (!count($this->convertTime)) {
97+
return 0.0;
98+
}
99+
100+
return array_sum($this->convertTime) / count($this->convertTime);
101+
}
102+
103+
public function getInsertTime(): float
104+
{
105+
if (!count($this->insertTime)) {
106+
return 0.0;
107+
}
108+
109+
return array_sum($this->insertTime) / count($this->insertTime);
110+
}
59111
}

0 commit comments

Comments
 (0)