WordPress Quotes Collection patch update

July 11th, 2011

This is an update to the WordPress Quotes Collection plugin, which uses “ORDER BY RAND().” This is a Bad Idea, but there is a better way that isn’t too ugly. This is a partial fix. A complete fix involves a helper table and a database trigger, which I am just too lazy to maintain as a branch of an uncommented PHP script.

The problem: If you have a very large number of quotes, and use the “random” feature, your quotes collection plugin is eating randomness very rapidly for each page load. This is bad.

The solution: This patch replaces the quotescollection_get_quote()  function with a random function that retrieves exactly one random number per fetch. It has only been tested in my configuration, with Quotes Collection 1.5.1:

function quotescollection_get_quote($condition = '', $random = 1, $current = 0)
{
    global $wpdb;
    $sql = "SELECT quote_id, quote, author, source
        FROM " . $wpdb->prefix . "quotescollection";
    if(!$random) {
        if ($condition)
            $sql .= $condition;
        if($current)
            $sql .= " AND quote_id < {$current}";
        $sql .= " ORDER BY quote_id DESC";
    }
    else {
                // Select random id. Conserves randomness, but will be less random if you
                // delete quotes.
                // See: http://jan.kneschke.de/projects/mysql/order-by-rand/
        $sql .= " JOIN (SELECT CEIL(RAND() * (SELECT MAX(quote_id)
                                FROM " . $wpdb->prefix . "quotescollection )) AS id)
                               AS myrand";

        if ($condition) {
            $sql .= $condition;
            $sql .= " AND ";
        }
        else {
            $sql .= " WHERE ";
        }

                $sql .= "quote_id >= myrand.id";
        // This random method requires LIMIT 1, which is appended below already
    }

    $sql .= " LIMIT 1";
    $random_quote = $wpdb->get_row($sql, ARRAY_A);
    if ( empty($random_quote) ) {
        if(!$random && $current)
            return quotescollection_get_quote($condition, 0, 0);
        else
            return 0;
    }
    else
        return $random_quote;
}

My previous random fix used count(*) which I have now discovered can be just as slow, for entirely different reasons. So I won’t be doing that again. :)

Peace, love, and high quality randomness to you all.

The Samamp In Its Natural Habitat

June 25th, 2011

The Samamp Bass Preamp in various scenic locations.

At a tiny dive bar along the highway:

Roadhouse Setup

Actually, these gigs pay pretty well...

Shown here with a tiny Ashdown practice combo and the Fernandez with Rio Grande Muy Grande pickups. The Bergantino is actually the PA.

On April 20, at a gig in front of a dispensary:

Bass Rig At Solace

Outdoors

I don’t think the employees would have believed it, but we were depressingly sober! Free burgers. Very pleasant. Samamp + Bergantino is a magical combination.

Tracking in the practice space:

With the Genz

Super Sweet

with the redbox DI and the Ibanez ATK. I’m just using the power stage of the Genz  Benz here, but it is a great amp on its own. Note the large quantity of empties being removed in the background.

Full biamped rig at the Outlaw Saloon:

Sweater Vest

At the Outlaw Saloon

Yes, that’s a sweater-vest. You have to be fashionable!

Appropriate tie for a wedding?

June 25th, 2011

So, apparently I now have this really cool tie.

The Skull Tie

Pirate Casual

The strange thing about this fairly awesome dark navy skull-and-crossbones tie is that it just sort of appeared in my shopping bag, along with a nice suit and “safe” tie that I purchased months ago and am just now unbagging. (I don’t really go formal very often, if at all.) According to the receipt, I didn’t pay for it either. That seems appropriate for a pirate-themed tie.

Anyway, I bought (or at least acquired) it months ago at a store in another state, so I guess it’s mine now. Since this is the era of pirate media, I thought it would be appropriate to upload it so everyone else can have a copy.

Yo ho.