Optimizing wp-quotes
Wednesday 5 July 2006 @ 1:03 pm

A few people have pointed out an inefficiency in the wp-quotes plugin. My plugin grabs every quote in your database, sticks in a PHP array, and then chooses a random member of that array. It’s slow, but it works. Some people have pointed out that mysql supports an “order by rand()” clause that will automagically choose a random element from the result set. This is true, but the version of MySQL I have in this server doesn’t support the rand option properly. To use it, you need mysql 3.23.56 or above.

Yes, I should be on MySQL 5.0, but I don’t control this server, so I work with what I’m given. An option in the plugin will be available in the next version if you know your version of MySQL supports it. I’ll be starting a refactoring/redesign soon, and it will include proper wordpress 2.0 support, proper admin support (via the options panel instead of the manage panel), and probably a widget version. Thanks to everyone who uses the plugin!

- Posted in WP-Quotes by Dustin  




13 Responses to 'Optimizing wp-quotes'

  1. c - July 5th, 2006 at 8:48 pm

    Hey, thank you for the plugin, Dustin. Glad to hear that you’re still developing on it, and looking forward to version 2.0 (or whatever it’ll be).

  2. christine - July 21st, 2006 at 9:29 pm

    Dustin, I just LOVE this plugin — I’m so happy to hear that you are working on a widget for it. (I haven’t been able to use wp-quotes since I changed my layout because I can’t figure out where to put the code. I *really* miss it! Thanks so much for continuing your hard work… I am eagerly awaiting the results. :)

  3. human-powered - September 2nd, 2006 at 3:47 pm

    I love wp-quotes - I post more quotes than I do blog entries.
    Just saying thanks for keeping it current and making it better, I look forward to the new versions.

  4. Ana - November 21st, 2006 at 10:40 pm

    si, gracias por el plugin, en serio. Este plugin es una parte muy central de mi blog. Me gusta mucho :)

  5. round can lose game - January 10th, 2007 at 6:45 am

    Very nice. I hope you’ll update very soon. right plane will love corner without any questions

  6. how to rotate taglines on your WordPress blog » Andy C - January 29th, 2007 at 7:03 am

    […] All that remains is the interesting part - performance tuning. No - wait. Existing users have already identified this modification as efficiently fetching a single, random record. Horribly database specific of course but worth having when you have 2.4 million quotes. […]

  7. sdgsdg - May 2nd, 2007 at 4:54 pm

    dgsgdsgds gds

  8. Anonymous - May 7th, 2007 at 1:50 pm

    For legacies sake you could just get the row count (I use “SELECT COUNT(1) FROM “) and then use the built in PHP rand function (preferably the Mersenne Twister) with the LIMIT clause to select a random row.

    LIMIT ,1 //offset being the desired row

  9. Kai - May 27th, 2007 at 6:24 am

    Hi. I wanted a daily quote in my sidebar (like MOTD), so I took your plugin and changed it for my needs. It reads the quotes descending from the database and taggs it with a timestampt starting the date I began with it. I even have a kind of quote archive (click on the three dots in the upper right), but it isn’t devided into pages, so in the future the page will be very long. Maybe I find someone who helps me rewriting the code or figure it out myself. Thanks anyway for your plugin! Bye

  10. S.K - October 7th, 2007 at 11:42 am

    How can I show a specific number of quotes on a page instead of the whole lot?

    I want to make multiple pages, each showing a specific number of quotes from the database.

    Please help. Thanks

    S.K

  11. Be a Good Daughter - October 19th, 2007 at 4:07 am

    Hi your message is amazing.
    I like your diary..
    See ya

  12. Dude - November 9th, 2007 at 2:46 pm

    Instead of having a order by you also could do something like

    while(didn’t fetch a valid quote){
    mysql_query(select form quotes where quote_id = random())
    }

  13. Dude - November 9th, 2007 at 2:49 pm

    Damn I didn’t write what I really wanted too… it would be nice to have a “quote added” field and a display for that. ;)


Leave a Reply