Yet Another Related Posts Plugin (YARPP) - Version 3.4.4b1

Version Description

Download this release

Release Info

Developer mitchoyoshitaka
Plugin Icon 128x128 Yet Another Related Posts Plugin (YARPP)
Version 3.4.4b1
Comparing to
See all releases

Code changes from version 3.4.3 to 3.4.4b1

Files changed (4) hide show
  1. cache-tables.php +8 -6
  2. class-cache.php +22 -12
  3. readme.txt +8 -1
  4. yarpp.php +2 -2
cache-tables.php CHANGED
@@ -190,10 +190,12 @@ class YARPP_Cache_Tables extends YARPP_Cache {
190
if ( !$reference_ID = absint($reference_ID) )
191
return YARPP_NOT_CACHED;
192
193
- $original_related = $this->related($reference_ID);
194
195
- // clear out the cruft
196
- $this->clear($reference_ID);
197
198
$wpdb->query("insert into {$wpdb->prefix}" . YARPP_TABLES_RELATED_TABLE . " (reference_ID,ID,score) " . $this->sql($reference_ID) . " on duplicate key update date = now()");
199
@@ -204,7 +206,7 @@ class YARPP_Cache_Tables extends YARPP_Cache {
204
if ($this->core->debug) echo "<!--YARPP just set the cache for post $reference_ID-->";
205
206
// Clear the caches of any items which are no longer related or are newly related.
207
- if (count($original_related)) {
208
$this->clear(array_diff($original_related, $new_related));
209
$this->clear(array_diff($new_related, $original_related));
210
}
@@ -244,12 +246,12 @@ class YARPP_Cache_Tables extends YARPP_Cache {
244
}
245
246
// return a list of ID's of "related" entries
247
- if (!is_null($reference_ID)) {
248
return $wpdb->get_col("select distinct ID from {$wpdb->prefix}" . YARPP_TABLES_RELATED_TABLE . " where reference_ID = $reference_ID and ID != 0");
249
}
250
251
// return a list of entities which list this post as "related"
252
- if (!is_null($related_ID)) {
253
return $wpdb->get_col("select distinct reference_ID from {$wpdb->prefix}" . YARPP_TABLES_RELATED_TABLE . " where ID = $related_ID");
254
}
255
190
if ( !$reference_ID = absint($reference_ID) )
191
return YARPP_NOT_CACHED;
192
193
+ $original_related = (array) @$this->related($reference_ID);
194
195
+ if ( count($original_related) ) {
196
+ // clear out the cruft
197
+ $this->clear($reference_ID);
198
+ }
199
200
$wpdb->query("insert into {$wpdb->prefix}" . YARPP_TABLES_RELATED_TABLE . " (reference_ID,ID,score) " . $this->sql($reference_ID) . " on duplicate key update date = now()");
201
206
if ($this->core->debug) echo "<!--YARPP just set the cache for post $reference_ID-->";
207
208
// Clear the caches of any items which are no longer related or are newly related.
209
+ if ( count($original_related) ) {
210
$this->clear(array_diff($original_related, $new_related));
211
$this->clear(array_diff($new_related, $original_related));
212
}
246
}
247
248
// return a list of ID's of "related" entries
249
+ if ( !is_null($reference_ID) ) {
250
return $wpdb->get_col("select distinct ID from {$wpdb->prefix}" . YARPP_TABLES_RELATED_TABLE . " where reference_ID = $reference_ID and ID != 0");
251
}
252
253
// return a list of entities which list this post as "related"
254
+ if ( !is_null($related_ID) ) {
255
return $wpdb->get_col("select distinct reference_ID from {$wpdb->prefix}" . YARPP_TABLES_RELATED_TABLE . " where ID = $related_ID");
256
}
257
class-cache.php CHANGED
@@ -134,7 +134,7 @@ abstract class YARPP_Cache {
134
* SQL!
135
*/
136
137
- function sql( $reference_ID = false, $args = array() ) {
138
global $wpdb, $post;
139
140
if ( is_object($post) && !$reference_ID ) {
@@ -171,7 +171,15 @@ abstract class YARPP_Cache {
171
// 1 means don't consider:
172
if ($value == 1)
173
continue;
174
- $tax_criteria[$tax] = "count(distinct if( termtax.taxonomy = '$tax', refterms.term_taxonomy_id, null ))";
175
$newsql .= " + " . $tax_criteria[$tax];
176
}
177
@@ -179,13 +187,16 @@ abstract class YARPP_Cache {
179
180
$newsql .= "\n from $wpdb->posts \n";
181
182
- // Get disallowed categories and tags
183
- $disterms = wp_parse_id_list(join(',',$exclude));
184
- $usedisterms = count($disterms);
185
- if ( $usedisterms || count($tax_criteria) ) {
186
- $newsql .= "left join $wpdb->term_relationships as terms on ( terms.object_id = $wpdb->posts.ID ) \n"
187
- . "left join $wpdb->term_taxonomy as termtax on ( terms.term_taxonomy_id = termtax.term_taxonomy_id ) \n"
188
- . "left join $wpdb->term_relationships as refterms on ( terms.term_taxonomy_id = refterms.term_taxonomy_id and refterms.object_id = $reference_ID ) \n";
189
}
190
191
// WHERE
@@ -208,9 +219,8 @@ abstract class YARPP_Cache {
208
// number_format fix suggested by vkovalcik! :)
209
$safethreshold = number_format(max($threshold,0.1), 2, '.', '');
210
$newsql .= " having score >= $safethreshold";
211
- if ( $usedisterms ) {
212
- $disterms = implode(',', $disterms);
213
- $newsql .= " and bit_or(termtax.term_id in ($disterms)) = 0";
214
}
215
216
foreach ( $weight['tax'] as $tax => $value ) {
134
* SQL!
135
*/
136
137
+ protected function sql( $reference_ID = false, $args = array() ) {
138
global $wpdb, $post;
139
140
if ( is_object($post) && !$reference_ID ) {
171
// 1 means don't consider:
172
if ($value == 1)
173
continue;
174
+
175
+ // @todo maybe reinforce the object term cache?
176
+ $terms = get_the_terms($reference_ID, $tax);
177
+ // if there are no terms of that tax, it's not worth adding it here.
178
+ if ( false === $terms )
179
+ continue;
180
+
181
+ $tt_ids = wp_list_pluck($terms, 'term_taxonomy_id');
182
+ $tax_criteria[$tax] = "count(distinct if( terms.term_taxonomy_id in (" . join(',',$tt_ids) . "), terms.term_taxonomy_id, null ))";
183
$newsql .= " + " . $tax_criteria[$tax];
184
}
185
187
188
$newsql .= "\n from $wpdb->posts \n";
189
190
+ // @todo do this just once in a schema migration
191
+ // Get term_taxonomy_ids of disallowed terms
192
+ $exclude_tt_ids = array();
193
+ foreach ($exclude as $tax => $term_ids) {
194
+ if ( !empty($term_ids) )
195
+ $exclude_tt_ids = array_merge( wp_list_pluck(get_terms( $tax, array('include' => $term_ids) ), 'term_taxonomy_id'), $exclude_tt_ids );
196
+ }
197
+
198
+ if ( count($exclude_tt_ids) || count($tax_criteria) ) {
199
+ $newsql .= "left join $wpdb->term_relationships as terms on ( terms.object_id = $wpdb->posts.ID ) \n";
200
}
201
202
// WHERE
219
// number_format fix suggested by vkovalcik! :)
220
$safethreshold = number_format(max($threshold,0.1), 2, '.', '');
221
$newsql .= " having score >= $safethreshold";
222
+ if ( count($exclude_tt_ids) ) {
223
+ $newsql .= " and bit_or(terms.term_taxonomy_id in (" . join(',', $exclude_tt_ids) . ")) = 0";
224
}
225
226
foreach ( $weight['tax'] as $tax => $value ) {
readme.txt CHANGED
@@ -5,7 +5,7 @@ Author URI: http://mitcho.com/
5
Plugin URI: http://yarpp.org/
6
Donate link: http://tinyurl.com/donatetomitcho
7
Tags: related, posts, post, pages, page, RSS, feed, feeds
8
- Requires at least: 3.1
9
Tested up to: 3.3
10
Stable tag: 3.4.3
11
@@ -173,6 +173,13 @@ If you are a bilingual speaker of English and another language and an avid user
173
174
== Changelog ==
175
176
= 3.4.3 =
177
* Bugfix: keywords were not getting cleared on post update, meaning new posts (which start blank) were not getting useful title + body keyword matches. This often resulted in "no related posts" for new posts.
178
* Postmeta cache: make sure to clear keyword cache on flush too
5
Plugin URI: http://yarpp.org/
6
Donate link: http://tinyurl.com/donatetomitcho
7
Tags: related, posts, post, pages, page, RSS, feed, feeds
8
+ Requires at least: 3.0
9
Tested up to: 3.3
10
Stable tag: 3.4.3
11
173
174
== Changelog ==
175
176
+ = 3.4.4 =
177
+ * Further main query optimization:
178
+ * What's cooler than joining four tables? Joining two.
179
+ * Exclude now simply uses `term_taxonomy_id`s instead of `term_id`s
180
+ * Don't clear the cache when it's already empty
181
+ * `protect` the `sql` method as it shouldn't be `public`
182
+
183
= 3.4.3 =
184
* Bugfix: keywords were not getting cleared on post update, meaning new posts (which start blank) were not getting useful title + body keyword matches. This often resulted in "no related posts" for new posts.
185
* Postmeta cache: make sure to clear keyword cache on flush too
yarpp.php CHANGED
@@ -3,13 +3,13 @@
3
Plugin Name: Yet Another Related Posts Plugin
4
Plugin URI: http://yarpp.org/
5
Description: Returns a list of related entries based on a unique algorithm for display on your blog and RSS feeds. A templating feature allows customization of the display.
6
- Version: 3.4.3
7
Author: mitcho (Michael Yoshitaka Erlewine)
8
Author URI: http://mitcho.com/
9
Donate link: http://tinyurl.com/donatetomitcho
10
*/
11
12
- define('YARPP_VERSION', '3.4.3');
13
define('YARPP_DIR', dirname(__FILE__));
14
define('YARPP_NO_RELATED', ':(');
15
define('YARPP_RELATED', ':)');
3
Plugin Name: Yet Another Related Posts Plugin
4
Plugin URI: http://yarpp.org/
5
Description: Returns a list of related entries based on a unique algorithm for display on your blog and RSS feeds. A templating feature allows customization of the display.
6
+ Version: 3.4.4b1
7
Author: mitcho (Michael Yoshitaka Erlewine)
8
Author URI: http://mitcho.com/
9
Donate link: http://tinyurl.com/donatetomitcho
10
*/
11
12
+ define('YARPP_VERSION', '3.4.4b1');
13
define('YARPP_DIR', dirname(__FILE__));
14
define('YARPP_NO_RELATED', ':(');
15
define('YARPP_RELATED', ':)');