Post by Nova » Mon Nov 12, 2007 12:27 pm

when i turn on debug database query, it take double quey. I found this cause:

Code: Select all

  function getRows($sql) {
$this->query($sql);

if (func_num_args()) {
    $this->query(implode(func_get_args(), ', '));
}

    $rows = array();

    while ($row = mysql_fetch_assoc($this->result)) {
$rows[] = $row;
    }

    mysql_free_result($this->result);

    return $rows;
  }
So, can i remove function: func_num_args()? What does it action?

Code: Select all

if (func_num_args()) {
    $this->query(implode(func_get_args(), ', '));
}

Newbie

Posts

Joined
Mon Nov 12, 2007 12:14 pm

Post by Nova » Mon Nov 12, 2007 12:29 pm

Debug :

Code: Select all

select * from setting where type = 'catalog' or type = 'global'( in 0.000792980194092 )

select * from setting where type = 'catalog' or type = 'global'( in 0.000777959823608 )

select value from session where session_id = 'ca8380abf8fddad97092886c426a51c8' and expire > '1194841709'( in 0.000821828842163 )

select * from url_alias where alias = 'controller=home'( in 0.000696897506714 )

select country_id, zone_id from address where address_id = '0' and customer_id = '6'( in 0.000530004501343 )

select tr.tax_class_id, sum(tr.rate) as rate, tr.description from tax_rate tr left join zone_to_geo_zone z2gz on (tr.geo_zone_id = z2gz.geo_zone_id) left join geo_zone gz on (tr.geo_zone_id = gz.geo_zone_id) where (z2gz.country_id = '0' or z2gz.country_id = '230') and (z2gz.zone_id = '0' or z2gz.zone_id = '3776') group by tr.tax_class_id( in 0.000525951385498 )

select tr.tax_class_id, sum(tr.rate) as rate, tr.description from tax_rate tr left join zone_to_geo_zone z2gz on (tr.geo_zone_id = z2gz.geo_zone_id) left join geo_zone gz on (tr.geo_zone_id = gz.geo_zone_id) where (z2gz.country_id = '0' or z2gz.country_id = '230') and (z2gz.zone_id = '0' or z2gz.zone_id = '3776') group by tr.tax_class_id( in 0.000453948974609 )

select * from weight_class where language_id = '1'( in 0.000576972961426 )

select * from weight_class where language_id = '1'( in 0.000411033630371 )

select * from weight_rule( in 0.000355005264282 )

select * from weight_rule( in 0.00029182434082 )

select * from product p left join product_description pd on (p.product_id = pd.product_id) left join image i on (p.image_id = i.image_id) where p.product_id = '1' and pd.language_id = '1' and p.date_available < now() and p.status = '1'( in 0.000588893890381 )

select o.name as name, ov.name as `value`, p2o.price, p2o.prefix from product_to_option p2o left join `option` o on p2o.option_id = o.option_id left join option_value ov on p2o.option_value_id = ov.option_value_id where p2o.product_to_option_id = '26' and product_id = '1' and o.language_id = '1' and ov.language_id = '1'( in 0.000497102737427 )

select o.name as name, ov.name as `value`, p2o.price, p2o.prefix from product_to_option p2o left join `option` o on p2o.option_id = o.option_id left join option_value ov on p2o.option_value_id = ov.option_value_id where p2o.product_to_option_id = '28' and product_id = '1' and o.language_id = '1' and ov.language_id = '1'( in 0.00043797492981 )

select * from product_discount where product_id = '1' and quantity <= '2' order by quantity desc limit 1( in 0.000403165817261 )

select * from product_to_download p2d left join download d on (p2d.download_id = d.download_id) left join download_description dd on (d.download_id = dd.download_id) where p2d.product_id = '1' and dd.language_id = '1'( in 0.000386953353882 )

select * from product_to_download p2d left join download d on (p2d.download_id = d.download_id) left join download_description dd on (d.download_id = dd.download_id) where p2d.product_id = '1' and dd.language_id = '1'( in 0.000367164611816 )

select * from customer where customer_id = '6'( in 0.000424861907959 )

update customer set cart = 'a:1:{s:7:\"1:26.28\";s:1:\"2\";}', ip = '127.0.0.1' where customer_id = '6'( in 0.000478982925415 )

select * from extension where type = 'module' group by code( in 0.000833034515381 )

select * from extension where type = 'module' group by code( in 0.000602960586548 )

select * from url_alias( in 0.000540971755981 )

select * from url_alias( in 0.000284910202026 )

select * from product p left join product_description pd on (p.product_id = pd.product_id) left join image i on (p.image_id = i.image_id) where p.status = '1' and pd.language_id = '1' and p.date_available < now() and p.status = '1' order by p.date_added limit 6( in 0.00698900222778 )

select * from product p left join product_description pd on (p.product_id = pd.product_id) left join image i on (p.image_id = i.image_id) where p.status = '1' and pd.language_id = '1' and p.date_available < now() and p.status = '1' order by p.date_added limit 6( in 0.00679516792297 )

select c.category_id, cd.name from category c left join category_description cd on (c.category_id = cd.category_id) where parent_id = '0' and language_id = '1' order by c.sort_order( in 0.000683069229126 )

select c.category_id, cd.name from category c left join category_description cd on (c.category_id = cd.category_id) where parent_id = '0' and language_id = '1' order by c.sort_order( in 0.000461101531982 )

select r.review_id, r.rating, r.text, p.product_id, pd.name, i.filename from review r left join product p on(r.product_id = p.product_id) left join product_description pd on(p.product_id = pd.product_id) left join image i on(p.image_id = i.image_id) where p.status = '1' and pd.language_id = '1' and p.date_available < now() and p.status = '1' and r.status = '1' order by rand() limit 1( in 0.0037670135498 )

Queries :28
Page created in 0.1815 seconds

Newbie

Posts

Joined
Mon Nov 12, 2007 12:14 pm

Post by gary » Tue Nov 13, 2007 2:53 am

are you saying that opencart executes most queries twice?

New member

Posts

Joined
Sun Nov 04, 2007 11:55 pm

Post by ogun » Tue Nov 13, 2007 5:12 am

'func_get_args' allows getRows to take an unspecified number of parameters. it's there in case the query being passed contains calls to work out stuff that hasn't already been worked out.

what happens if you replace:
[php]
function getRows($sql) {
$this->query($sql);

if (func_num_args()) {
$this->query(implode(func_get_args(), ', '));
}

$rows = array();

while ($row = mysql_fetch_assoc($this->result)) {
$rows[] = $row;
}

mysql_free_result($this->result);

return $rows;
}
[/php]
with:
[php]
function getRows($sql) {
//$this->query($sql);

//if (func_num_args()) {
$this->query(implode(func_get_args(), ', '));
//}

$rows = array();

while ($row = mysql_fetch_assoc($this->result)) {
$rows[] = $row;
}

mysql_free_result($this->result);

return $rows;
}
[/php]

Active Member

Posts

Joined
Tue Aug 14, 2007 6:04 am

Post by Nova » Tue Nov 13, 2007 9:41 am

gary wrote: are you saying that opencart executes most queries twice?
Yes,


Tks,It worked well :
  function getRows($sql) {


if (func_num_args()) {
    $this->query(implode(func_get_args(), ', '));
}
else{
$this->query($sql);
}

    $rows = array();

    while ($row = mysql_fetch_assoc($this->result)) {
$rows[] = $row;
    }

    mysql_free_result($this->result);

    return $rows;
  }

Newbie

Posts

Joined
Mon Nov 12, 2007 12:14 pm

Post by gary » Wed Nov 14, 2007 12:57 am

Thank you - very helpful info

New member

Posts

Joined
Sun Nov 04, 2007 11:55 pm

Post by ogun » Thu Aug 14, 2008 10:58 pm

this is still the case in 0.7.8. getRows runs queries twice, the first time without sending the results anywhere.

Active Member

Posts

Joined
Tue Aug 14, 2007 6:04 am

Post by hm2k » Thu Sep 04, 2008 10:34 pm


UK Web Hosting


User avatar
Global Moderator

Posts

Joined
Tue Mar 11, 2008 9:06 am
Location - UK
Who is online

Users browsing this forum: No registered users and 3 guests