PHP Events onpreload

Maud67

New Member
Hi,

I hope that somebody can advice me on the following:

I have two big tables/lists.

One will be updated every week with data (import) for the next week.
The other one will be updated every weekday with data (import) for the next weekday.

On the second list I have a php events plugin with the following code:

$myDb = JFactory::getDbo();
$myQuery = $myDb->getQuery(true);

$myQuery
-> update('jos_1b_import_transporter_daily1 AS t')
-> join('INNER','jos_1b_import_transporter AS a ON t.projekt_namn = a.projekt_namn')
-> set('t.text_1 = a.trailertyp_ba')
-> where('t.lass_nr = a.lass_nr AND t.leverans_datum >= NOW()');

$myDb->setQuery($myQuery);
$myDb->execute();

This I have three times for three columns.

Please note that the "leverans_datum" is a field and no date element.

Without the code the list loads normal.
With the code the list loads slow.

What do I do wrong and how can I improve the loading speed?

Thanks a lot!
 
Do you have indexes for all relevant elements (projekt_namn, lass_nr, leverans_datum)? You must create them directly in your database.

Why do you run the code three times? You can set three columns in one query.
 
Hi Troester,

Thanks for responding.

I just finished checking the indexes and they are ok.

I know that I can put it in one query but I'm not sure how.
I did read it somewhere in a threat where Hugh explained how but I cannot find it.

Can you help me please?

Thanks!
 
Hi Troester,

I was thinking, I guess I can copy add the other two set rows.

I will try that.

Thanks!
 
set (' x1= y1, x2=y2') should do

if it's the same condition

Gesendet von meinem SM-G930F mit Tapatalk
 
You can either do what Troester suggested, or use multiple set() function. I prefer to do the latter, as it makes it clearer in the code you are setting multiple fields ...

Code:
$myQuery
->update('jos_1b_import_transporter_daily1 AS t')
->join('INNER','jos_1b_import_transporter AS a ON t.projekt_namn = a.projekt_namn')
->set('t.text_1 = a.trailertyp_ba')
->set('t.foo = a.foo')
->set('t.bar = a.bar')
->where('t.lass_nr = a.lass_nr AND t.leverans_datum >= NOW()');

-- hugh
 
Also, as Troester says, make sure you have indexes on anything you join on, and anything you filter on ... so t.projekt_namn, a.projekt_namn, t.lass_nr, a.lass_nr , t.leverans_datum. If you have filters in Fabrik set up on those elements, you may already have indexes, but definitely check with phpMyAdmin (or whatever), and if necessary add them by hand - standard BTREE indexes are fine.

-- hugh
 
Hi Hugh,

A little late sorry, but I have indexes on every element.
It is working fine now.

Thanks a lot!
 
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top