PDA

View Full Version : performance: postbit_display_complete hook


al3bed
10-05-2009, 10:56 PM
hello,

I face a performance problem with postbit_display_complete hook. this hook can't read from other hooks such as global_start and parse_templates? also this hook can't replace str from forum templates? I used a fetch_array function in parse_templates to declare variables fetching a template like below:

/* ADS VARIABLES */
$vbulletin->db->hide_errors();
$ain_info = $vbulletin->db->query_read("
SELECT id, type, content, slot, channel, width, height
FROM " . TABLE_PREFIX . "ainads AS ainads
ORDER BY id ASC ");

while ($ain_data = $vbulletin->db->fetch_array($ain_info))
{
$ainads_doneid = $ain_data[id];
eval('$ain_ads[$ainads_doneid] .= "' . fetch_template('ain_showads') . '";');
}
$vbulletin->db->show_errors();
/* END ADS VARIABLES */

this will give me 3 queries executed in normal case if I have 3 raws of data.
but if i but this code in postbit hook will execute each time postbit show.. so
if I have a 10 posts within the page it's will give me 3*10= 30 queries! too much

how can I solve this? I want to use the variables templates called by postbit_display_complete, but they don't work if I don't but the code in the hook.

hope it's clear enough?
sorry for my bad english

thanks

Lynne
10-06-2009, 12:02 AM
Why use the postbit_display_complete hook if you don't want it run each time a postbit is displayed? I fyou only want it run once per page on a thread, then pic another hook location (a showthread_* one?). I don't see anything in that plugin that has to be run in the postbit hook location.

al3bed
10-06-2009, 07:29 AM
I use postbit_display_complete becuase I need to execute some codes inside postbit

the only one I don't want to execute it each time a postbit displayed is the code above.

but still I need to execute it once.

Q. If I put the previous code in a showthread_* one I can use VARIABLES declared there in postbit_display_complete?

Lynne
10-06-2009, 02:05 PM
I would try putting that in a plugin that uses in the correct showthread_* hook location (one that is run after the postbit_* hook you are using to create the variables) and see what happens. You may have to use the variable $GLOBALS['yourvariable'], but I would try without doing that first.