No image Organize Series plugin database optimization

While looking for posts in the series, this plugin makes two database queries for each post in the series : one to find out if the post is published, and another to get the part number in the series. So if you have 30 posts in the series, you will get 60 queries from this plugin alone on each post belonging to that series. I found this very wasteful, and rewrote one function so that it only uses one database query, no matter what the number of posts in the series. I think the author should be interested…

Basically, in the file series-utility.php, replace the function
function get_series_order($posts, $postid = 0, $skip = TRUE)
by the following one :

<?php
function get_series_order($posts, $postid = 0, $skip = TRUE) {
global $wpdb;
if (!isset($posts)) return false; //don’t have the posts array so can’t do anything.

if ( !is_array( $posts )
$posts = array($posts);

$series_posts = array();
$key = 0;

foreach ($posts as $spost) {
if (array_key_exists(‘object_id’, $posts)) {
if ($key!=0){
$spost_id .= “,”.$spost['object_id'];
}else{
$spost_id .= $spost['object_id'];
}
} else {
if ($key!=0){
$spost_id .= “,”.$spost;
}else{
$spost_id .= $spost;
}
}
$key++;
}

//Optimized : 1 SQL query instead of 2* number ofposts in series//
$results=$wpdb->get_results(“SELECT $wpdb->posts.ID, $wpdb->postmeta.meta_value
FROM $wpdb->posts LEFT JOIN $wpdb->postmeta
ON($wpdb->posts.ID = $wpdb->postmeta.post_id)
WHERE post_status = ‘publish’ AND $wpdb->posts.ID
IN (“.$spost_id.”) AND ener_postmeta.meta_key=’”.SERIES_PART_KEY.”‘”);
/* 208 – fix by Matt Porter – to make sure unpublished posts are not made part of a series */
foreach ($results as $num=>$result) {
//echo “<h1>resultat”.$result->ID.$result->meta_value.”</h1>”;
$series_posts[$num]['id'] =$result->ID;
$series_posts[$num]['part'] = $result->meta_value;
}

if (count($series_posts) > 1)
usort( $series_posts, ‘_usort_series_by_part’ );

return $series_posts;
}
?>

And there you go, a faster blog…

Show comments

No image Amazon Wishlist plugin for wordpress 2.7

Hello all,
After quite a few years out of the wordpress world, I’m back using this great CMS, and of course, I had to rewrite one of my old plugins to work with the widget interface.

Well, the Amazon wishlist plugin was the one I like best, and found really useful, although no-one ever bought me a book ;( (hint hint !)

It does not work through the normal API, but just pulls the wishlist page with curl and parses it. I did that because the amazon API does not allow priority sorting, which I find more than useful. You will need curl for that, though…

The widget is configurable, as you can see from the image on the right.
You can see it in action on this site about renewable energy

Download it!

Show comments

No image Ma vie sur le web

Grâce aux pipes de yahoo, vous pouvez suivre toutes mes interventions publiques sur le web. Il s’agit en fait d’une aggrégation de tous les flux RSS que je produit en un seul, classé par date. J’en ai sûrement oubliés, mais je peux toujours les rajouter par la suite. Liste provisoire :
- Ce blog
- Les Energies Vertes
- Flickr
- Twitter
- et del.icio.us

Show comments