findingpeace
08-19-2014, 07:44 PM
I've created a PHP Direct Execution CMS Widget with this code to count the number of donating members:
global $vbulletin;
$cmember = $vbulletin->db->query_read_slave("SELECT count(*) as num
FROM " . TABLE_PREFIX . "user AS user
WHERE user.usergroupid IN (9) OR FIND_IN_SET(9, membergroupids)");
$cmembers= $vbulletin->db->fetch_array($cmember);
$content = array('cmembers' => $cmembers[num]);
vB_Template::preRegister('vbcms_widget_mywidget',$ content);
Works great, except I set a 5 minute refresh cache, but every time I load the CMS, the debugger shows this query being run:
SELECT count(*) as num
FROM vbuser AS user
WHERE user.usergroupid IN (9) OR FIND_IN_SET(9, membergroupids)
Shouldn't this query only be running every 5 minutes? Right now, it's running on every single refresh, even just seconds later.
Thanks!
--------------- Added 1408560000 at 1408560000 ---------------
This was my own stupid fault. I just pasted in the plugin code, didn't actually set the variable to $output, which the widget instructions told me to do :)
Basically changed to this:
global $vbulletin;
$cmember = $vbulletin->db->query_read_slave("SELECT count(*) as num
FROM " . TABLE_PREFIX . "user AS user
WHERE user.usergroupid IN (9) OR FIND_IN_SET(9, membergroupids)");
$cmembers= $vbulletin->db->fetch_array($cmember);
$output = array('cmembers' => $cmembers[num]);
vB_Template::preRegister('vbcms_widget_mywidget',$ output);
global $vbulletin;
$cmember = $vbulletin->db->query_read_slave("SELECT count(*) as num
FROM " . TABLE_PREFIX . "user AS user
WHERE user.usergroupid IN (9) OR FIND_IN_SET(9, membergroupids)");
$cmembers= $vbulletin->db->fetch_array($cmember);
$content = array('cmembers' => $cmembers[num]);
vB_Template::preRegister('vbcms_widget_mywidget',$ content);
Works great, except I set a 5 minute refresh cache, but every time I load the CMS, the debugger shows this query being run:
SELECT count(*) as num
FROM vbuser AS user
WHERE user.usergroupid IN (9) OR FIND_IN_SET(9, membergroupids)
Shouldn't this query only be running every 5 minutes? Right now, it's running on every single refresh, even just seconds later.
Thanks!
--------------- Added 1408560000 at 1408560000 ---------------
This was my own stupid fault. I just pasted in the plugin code, didn't actually set the variable to $output, which the widget instructions told me to do :)
Basically changed to this:
global $vbulletin;
$cmember = $vbulletin->db->query_read_slave("SELECT count(*) as num
FROM " . TABLE_PREFIX . "user AS user
WHERE user.usergroupid IN (9) OR FIND_IN_SET(9, membergroupids)");
$cmembers= $vbulletin->db->fetch_array($cmember);
$output = array('cmembers' => $cmembers[num]);
vB_Template::preRegister('vbcms_widget_mywidget',$ output);