More bsuite Hacking

Update: bugfix release b2v6 available.

Some conversations with Chow Kah Soon, who’s site is full of diversions from work , finally convinced encouraged me to solve some small problems that were giving him big trouble. Chow Kah Soon is in the lucky, but rare, position of having over 20,000 unique daily visitors to his site, so he’s sort of my designated stress-tester.

After looking at the logs he shared with me, the table structure, and the queries in bsuite, it was pretty clear that I needed to make some changes to the indexes.

Optimizing the indexes was easy, but how can I make bsuite update those indexes on existing installs? That’s where these docs explaining WordPress’ rather unique dbDelta function come in:

Instead of using a normal $wpdb query to make our table, there is a special function in WordPress that we’ll use that can create a table if it isn’t there, or change the structure if it doesn’t match the current table. This will come in very handy if we ever need to make changes to the MySQL structure in the future.

The function’s a little finicky, and it took me a couple minutes to realize that it was tripping up on the backtick quotes (`) I had wrapped around my table and field names. But with that out of the way, it solves the big problem of how to easily add indexes to existing tables. What it doesn’t solve, sadly, is how to delete existing indexes that aren’t in the new table definition.

With the dbDelta function implemented, I also finally got around to implementing an auto-install hook that creates or re-configs the tables upon plugin activation. Here’s the example from the docs:

add_action('activate_pluginurl','jal_install');

But I had to Google for this support forum post to understand what the “pluginurl” should be.

…you simply have to use the path of your plugin relative to /wp-content/plugins. Eg: you have a plugin in /wp-content/plugins/wp-spamfilter/wp-spamfilter.php then you have to call add_action as following:

add_action(‘activate_wp-spamfilter/wp-spamfilter.php’, ’somefunction’);

Yes, all of these updates will be released soon. I promise.

bstat, bsuite, Chow Kah Soon, documentation, KahSoon.com, mysql, optimization, update, wordpress

4 thoughts on “More bsuite Hacking

  1. Looking forward to it!

    I’ve tried twice recently to deactivate this plugin so it is only active when I want to view it (thinking it would be less of a load, just like my wp-slimstat suggest doing for their’s) but each time I tried with bsuite, my blog site goes completely void of data; the only thing displayed is my theme lol. Needless to say, I leave it active all the time now, have you run across this before? TIA.

  2. Thanks for your great plugin!

    I’ve noticed a small error in bsuite.php on l. 753: instead of using the variable get_settings(‘home’) you should use the variable get_settings(‘siteurl’), otherwise you won’t get the right path to spacer.gif in case wordpress is not in the same directory as index.php.

    By the way, do you include RSS feeds in your stats?

  3. Thx for the response, guess I won’t be getting one for this either… no updates since I saw you visit yesterday. Interesting.

  4. Pingback: bsuite Bug Fixes (release b2v6) « MaisonBisson.com

Comments are closed.