Seite 1 von 1

Langsamer Seitenaufbau in der Produkt-Info

Verfasst: 24.02.2012, 10:08
von wolfschw
Hallo

Habe einige Produkte die schon über 5000 mal gekauft wurden.

Wenn eines von diesen Produkten im Online-Shop aufgerufen wird,
dauert der Seitenaufbau recht lang.
Wenn ich die Option Kunden kauften auch auf null setze, geht der Seitenaufbau zügig.

Beispiel Link http://www.jura-ersatzteile-shop.de/inf ... -p-50.html

Kann man diese Option Kunden kauften auch nicht anders erechnen ?
z.B. die gekauften Artikel nur aus den letzten 6 Monaten berechnen ?

gruß

Wolfgang

Verfasst: 24.02.2012, 15:00
von r23
Hallo,

ich wüsste zurzeit nicht - wie man die Abfrage optimieren könnte.

In der Regel reduzieren wir die Datensätze in der Datenbank.

Man könnte evtl. das Ergbnis der Abfrage speichern.
AdoDb biete eine Cache funktion an.
http://phplens.com/adodb/reference.func ... imite.html

~/modules/also_purchased_products.php

Code: Alles auswählen

    $sql = "SELECT p.products_id, p.products_image
            FROM $orders_productstable opa,
                 $orders_productstable opb,
                 $orderstable o,
                 $productstable p
            WHERE opa.products_id = '" . intval($nProductsId) . "'
              AND opa.orders_id = opb.orders_id
              AND opb.products_id != '" . intval($nProductsId) . "'
              AND opb.products_id = p.products_id
              AND opb.orders_id = o.orders_id
              AND p.products_status >= '1'
            GROUP BY p.products_id
            ORDER BY o.date_purchased DESC";
    $orders_result = $dbconn->SelectLimit($sql, MAX_DISPLAY_ALSO_PURCHASED);

Code: Alles auswählen

    $sql = "SELECT p.products_id, p.products_image
            FROM $orders_productstable opa,
                 $orders_productstable opb,
                 $orderstable o,
                 $productstable p
            WHERE opa.products_id = '" . intval($nProductsId) . "'
              AND opa.orders_id = opb.orders_id
              AND opb.products_id != '" . intval($nProductsId) . "'
              AND opb.products_id = p.products_id
              AND opb.orders_id = o.orders_id
              AND p.products_status >= '1'
            GROUP BY p.products_id
            ORDER BY o.date_purchased DESC";
    $dbconn->cacheSecs = 3600*24; // cache 24 hours
    $orders_result = $dbconn->CacheSelectLimit($sql, MAX_DISPLAY_ALSO_PURCHASED);
Dann würde der Shop nur einmal am Tag bei dem Produkt *hängen*

Leider funktioniert die Cache funktion nicht in jeder PHP Umgebung. Bitte prüfen...


Beste Grüße

ralf

Verfasst: 24.02.2012, 18:05
von r23
Hallo,

ich habe mal etwas in meinem Script Archive gesucht und für einen alten osCommerce dieses hier gefunden

Code: Alles auswählen

if (isset($HTTP_GET_VARS['products_id'])) {
$sub_orders_query = tep_db_query("select op.orders_id from " . TABLE_ORDERS_PRODUCTS . " op, " . TABLE_ORDERS . " o where products_id = '" . (int)$HTTP_GET_VARS['products_id'] . "' and op.orders_id = o.orders_id and DATE_SUB(CURDATE(), INTERVAL 720 DAY) <= o.date_purchased order by o.date_purchased desc limit 100"); // the last 100 orders with this product should suffice hopefully
if (($num_sub_products_ordered = tep_db_num_rows($sub_orders_query)) > 0) {
while ($sub_orders = tep_db_fetch_array($sub_orders_query)) {
$list_of_order_ids[] = $sub_orders['orders_id'];
}
}
// if there are no orders with this product the next query is pointless too
if (isset($list_of_order_ids)) {
$orders_query = tep_db_query("select p.products_id, p.products_image from " . TABLE_ORDERS_PRODUCTS . " opb, " . TABLE_ORDERS . " o, " . TABLE_PRODUCTS . " p where opb.products_id != '" . (int)$HTTP_GET_VARS['products_id'] . "' and opb.products_id = p.products_id and opb.orders_id = o.orders_id and o.orders_id in (" . implode(',', $list_of_order_ids) . ") and p.products_status = '1' group by p.products_id order by o.date_purchased desc limit " . MAX_DISPLAY_ALSO_PURCHASED);
$num_products_ordered = tep_db_num_rows($orders_query);
if ($num_products_ordered >= MIN_DISPLAY_ALSO_PURCHASED) {
?>
<!-- also_purchased_products //-->
<?php
$info_box_contents = array();
$info_box_contents[] = array('text' => TEXT_ALSO_PURCHASED_PRODUCTS);
new contentBoxHeading($info_box_contents);
$row = 0;
$col = 0;
$info_box_contents = array();
while ($orders = tep_db_fetch_array($orders_query)) {
$orders['products_name'] = tep_get_products_name($orders['products_id']);
$info_box_contents[$row][$col] = array('align' => 'center',
'params' => 'class="smallText" width="33%" valign="top"',
'text' => '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $orders['products_id']) . '">' . tep_image(DIR_WS_IMAGES . $orders['products_image'], $orders['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a><br><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $orders['products_id']) . '">' . $orders['products_name'] . '</a>');
$col ++;
if ($col > 2) {
$col = 0;
$row ++;
}
}
new contentBox($info_box_contents);
?>

Ich kann mir vorstellen, dass diese Datenbank-Abfrage schneller geht? wobei ich vermutlich nicht über 720 Tagen gehen würde?

Hilft diese Antwort weiter?

ralf

Verfasst: 26.02.2012, 07:22
von r23
ps:

Ich habe die Idee in das Projekt aufgenommen:

Hier die geänderte

http://www.oos-shop.de/service/oos17x/a ... oducts.txt

als PHP nach
~/shop/includes/modules/ kopieren.

Das Script ist unter MyOOS Version 1.80 getestet.

Beste Grüße

ralf

Verfasst: 26.02.2012, 10:46
von wolfschw
Ok

Vielen Dank

Jetzt ist der Seitenaufbau recht schnell

gruß