Improve performance. #762
This commit is contained in:
parent
5834e0a38f
commit
1f8f403970
1 changed files with 27 additions and 10 deletions
|
|
@ -61,11 +61,12 @@ class GetJobOrderArchiveDataCommand extends Command
|
|||
|
||||
$db = $this->em->getConnection();
|
||||
|
||||
// TODO: improve performance. out of memory exception
|
||||
$query_sql = 'SELECT *
|
||||
FROM job_order
|
||||
WHERE YEAR(date_create) = :year
|
||||
ORDER BY date_create
|
||||
LIMIT 100000';
|
||||
ORDER BY date_create
|
||||
LIMIT 150000';
|
||||
|
||||
$query_stmt = $db->prepare($query_sql);
|
||||
$query_stmt->bindValue('year', $year, PDO::PARAM_STR);
|
||||
|
|
@ -93,13 +94,22 @@ class GetJobOrderArchiveDataCommand extends Command
|
|||
$this->deleteDataFiles('invoice_item');
|
||||
|
||||
$archive_files = [];
|
||||
|
||||
$jo_id_list = [];
|
||||
|
||||
while ($row = $results->fetchAssociative())
|
||||
{
|
||||
$jo_data['job_order'][$row['id']] = $this->createJobOrderArchiveData($row);
|
||||
|
||||
// add jo id to jo_id_list
|
||||
$jo_id_list[] = $row['id'];
|
||||
}
|
||||
|
||||
// get all related data for job order
|
||||
foreach ($jo_id_list as $jo_id)
|
||||
{
|
||||
// foreach job order id we got from the first query, we get the JO related
|
||||
// data for that id from jo_event, invoice, ticket, jo_rejection, rider_rating
|
||||
|
||||
if (is_callable($callbackJO))
|
||||
{
|
||||
foreach ($related_tables as $table_name)
|
||||
|
|
@ -118,7 +128,7 @@ class GetJobOrderArchiveDataCommand extends Command
|
|||
$db = $this->em->getConnection();
|
||||
|
||||
$query_stmt = $db->prepare($query_sql);
|
||||
$query_stmt->bindValue('id', $row['id']);
|
||||
$query_stmt->bindValue('id', $jo_id);
|
||||
|
||||
$files = call_user_func($callbackJO, $row, $query_stmt, $table_name, $year);
|
||||
|
||||
|
|
@ -149,6 +159,7 @@ class GetJobOrderArchiveDataCommand extends Command
|
|||
|
||||
$data = [];
|
||||
$files = [];
|
||||
$invoice_id_list = [];
|
||||
|
||||
while ($q_row = $results->fetchAssociative())
|
||||
{
|
||||
|
|
@ -156,10 +167,8 @@ class GetJobOrderArchiveDataCommand extends Command
|
|||
// all invoice items for a specific invoice too
|
||||
if ($table_name == 'invoice')
|
||||
{
|
||||
// get invoice item related data
|
||||
$ii_file = $this->getInvoiceItemArchiveData($q_row, $year);
|
||||
|
||||
$files['invoice_item'] = $ii_file;
|
||||
// add invoice id to list
|
||||
$invoice_id_list[] = $q_row['id'];
|
||||
}
|
||||
|
||||
$fields = [];
|
||||
|
|
@ -173,6 +182,14 @@ class GetJobOrderArchiveDataCommand extends Command
|
|||
$data[$table_name][$q_row['id']] = $fields;
|
||||
}
|
||||
|
||||
// get the invoice items for archiving
|
||||
foreach ($invoice_id_list as $i_id)
|
||||
{
|
||||
$ii_file = $this->getInvoiceItemArchiveData($i_id, $year);
|
||||
|
||||
$files['invoice_item'] = $ii_file;
|
||||
}
|
||||
|
||||
// write the array into the file
|
||||
$file = $this->createDataFileRelatedArchiveData($data, $table_name, 'a');
|
||||
|
||||
|
|
@ -182,14 +199,14 @@ class GetJobOrderArchiveDataCommand extends Command
|
|||
return $files;
|
||||
}
|
||||
|
||||
protected function getInvoiceItemArchiveData($row, $year)
|
||||
protected function getInvoiceItemArchiveData($id, $year)
|
||||
{
|
||||
$db = $this->em->getConnection();
|
||||
|
||||
$query_sql = 'SELECT * FROM invoice_item WHERE invoice_id = :id';
|
||||
|
||||
$query_stmt = $db->prepare($query_sql);
|
||||
$query_stmt->bindValue('id', $row['id']);
|
||||
$query_stmt->bindValue('id', $id);
|
||||
|
||||
$results = $query_stmt->executeQuery();
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue