Last active
August 29, 2015 14:01
-
-
Save buldezir/82b60459437feb0e3d0b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$dbConn = \Doctrine\DBAL\DriverManager::getConnection(array( | |
'driver' => 'pdo_pgsql', | |
'dbname' => 'sasha', | |
'user' => 'sasha', | |
'password' => '', | |
'host' => 'localhost', | |
)); | |
Dja\Db\Model\Metadata::setDefaultDbConnection($dbConn); | |
register_shutdown_function(function () use ($dbConn) { | |
$dbConn->close(); | |
}); | |
class ModelCustomerOrder extends Dja\Db\Model\Model | |
{ | |
protected static $dbtable = 'customer_order'; | |
protected static $fields = [ | |
'customer_order_id' => ['Auto', 'help_text' => 'первичный ключ'], | |
'date_added' => ['DateTime', 'null' => true, 'help_text' => 'время создания'], | |
'delivery_price' => ['Float', 'null' => true, 'default' => '0', 'help_text' => 'стоимость доставки'], | |
'delivery_date' => ['Date', 'null' => true, 'help_text' => 'дата доставки'], | |
'comment' => ['Text', 'default' => '', 'blank' => true, 'help_text' => 'комментарий'], | |
'pre_weight' => ['Float', 'null' => true, 'help_text' => 'Вес, кг. Кэш'], | |
'pre_length' => ['Float', 'null' => true, 'help_text' => 'ширина, см. Кэш'], | |
'pre_width' => ['Float', 'null' => true, 'help_text' => 'глубина, см. Кэш'], | |
'pre_height' => ['Float', 'null' => true, 'help_text' => 'высота, см. Кэш'], | |
'pre_price' => ['Float', 'default' => '0', 'help_text' => 'стоимость всех товаров в заказе без стоимости доставки. кэш'], | |
//'user' => ['ForeignKey', 'relationClass' => 'ModelUser', 'db_column' => 'user_id', 'null' => true, 'help_text' => 'ссылка на ответственного менеджера БО'], | |
'address' => ['Text', 'default' => '', 'blank' => true, 'help_text' => 'адрес доставки. JSON-массивArray( [address] => 190005, Санкт-Петербург , Советский пер, дом 1 [kladr] => 1780000000001307 [params] => Array ( [postcode] => 190005 [house] => 1 [korp] => [str] => [apart] => [ajaxCity] => Санкт-Петербург [ajaxStreet] => Советский пер [hidden_postcode] => ))'], | |
'stock_order_number' => ['Int', 'null' => true, 'help_text' => 'номер заказа на объекте'], | |
'order_number' => ['Char', 'null' => true, 'max_length' => 21, 'default' => '', 'blank' => true, 'help_text' => 'полный номер заказа'], | |
'workflow_status' => ['ForeignKey', 'relationClass' => 'ModelWorkflowStatus', 'db_column' => 'workflow_status_id', 'null' => true, 'help_text' => 'статус документооборота'], | |
'passport' => ['Text', 'default' => '', 'blank' => true, 'help_text' => 'Паспортные данные. JSON-массив (ФИО - fio, серия паспорта - series, номер паспорта - number, кем выдан - police, дата выдачи - date)'], | |
'is_cc_sent' => ['Bool', 'default' => true, 'help_text' => 'Отправлен ли в КЦ (call-center)?'], | |
'workflow_date_edit' => ['DateTime', 'null' => true, 'help_text' => 'Дата последнего WF-перехода'], | |
'box_count' => ['Int', 'default' => 0, 'help_text' => 'Количество коробок, в которое упакован заказ'], | |
'workflow_status_reason' => ['ForeignKey', 'relationClass' => 'ModelWorkflowStatusReason', 'db_column' => 'workflow_status_reason_id', 'null' => true, 'help_text' => 'Причина установки статуса'], | |
'date_modified' => ['DateTime', 'null' => true, 'help_text' => 'Дата последнего изменения'], | |
'customer_name' => ['Char', 'max_length' => 255, 'default' => '', 'blank' => true, 'help_text' => 'имя покупателя'], | |
'has_act' => ['Bool', 'default' => true, 'help_text' => 'есть ли акт сдачи-приемки товаров?'], | |
'ip' => ['Char', 'null' => true, 'help_text' => 'IP-адрес покупателя'], | |
'delivery_full_price' => ['Float', 'null' => true, 'default' => '0', 'help_text' => 'стоимость доставки без учёта скидки'], | |
'linked_customer_orders' => ['Char', 'null' => true, 'max_length' => 200, 'help_text' => 'Связанные заказы'], | |
'claims' => ['Char', 'null' => true, 'max_length' => 200, 'help_text' => 'Претензии'], | |
'service_comment' => ['Text', 'default' => '', 'blank' => true, 'help_text' => 'служебный комментарий'], | |
'pre_full_price' => ['Float', 'null' => true, 'help_text' => 'Оценочная стоимость заказа'], | |
'index_number' => ['Int', 'null' => true, 'help_text' => 'Порядковый номер заказа'], | |
]; | |
} | |
function testBigSelectArray($limit) | |
{ | |
$db = Dja\Db\Model\Metadata::getDefaultDbConnection(); | |
$t1 = microtime(1); | |
$m1 = memory_get_usage(1); | |
$raw = $db->fetchAll('SELECT ' . implode(',', ModelCustomerOrder::metadata()->getDbColNames()) . ' FROM customer_order LIMIT ' . $limit); | |
foreach ($raw as $i => &$row) { | |
} | |
$t2 = microtime(1); | |
$m2 = memory_get_usage(1); | |
$d1 = $m2 - $m1; | |
echo 'delta: ' . formatBytes($d1) . PHP_EOL; | |
echo 'exec in ' . round(($t2 - $t1), 3) . ' s' . PHP_EOL; | |
echo 'peak: ' . formatBytes(memory_get_peak_usage(1)) . PHP_EOL; | |
} | |
function testBigSelectObj($limit) | |
{ | |
ModelCustomerOrder::metadata(); | |
$t1 = microtime(1); | |
$m1 = memory_get_usage(1); | |
$q = ModelCustomerOrder::objects()->limit($limit); //->selectRelated('stock', 'customer'); //->noCache(); | |
$ids = []; | |
foreach ($q->cached() as $i => $row) { | |
$ids[] = $row->customer_order_id; | |
$tmp = $row->workflow_status_id; | |
//$row->workflow_status_id = 1; // overhead for cleanData copy | |
//if ($i > 2000) break; | |
} | |
echo "uniques: " . count(array_unique($ids)) . PHP_EOL; | |
unset($ids); | |
$t2 = microtime(1); | |
$m2 = memory_get_usage(1); | |
$d1 = $m2 - $m1; | |
echo 'delta: ' . formatBytes($d1) . PHP_EOL; | |
echo 'exec in ' . round(($t2 - $t1), 3) . ' s' . PHP_EOL; | |
echo 'peak: ' . formatBytes(memory_get_peak_usage(1)) . PHP_EOL; | |
} | |
$limit = 10000; | |
// запускать лучше отдельно | |
//testBigSelectArray($limit); | |
//testBigSelectObj($limit); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment