Skip to content
Snippets Groups Projects
db-hash.php 449 B
Newer Older
<?php

require_once('flexihash.php');

$wpdb_hash = new Flexihash();

/* Hashing function to map blogs to databases.
 *
 * Implements a consistent hashing scheme using Flexihash.
 */
function noblogs_db_callback($query, $wpdb) {
  global $wpdb_hash;
  if (preg_match("/^{$wpdb->base_prefix}(\d+)_/", $wpdb->table, $matches)) {
    $blog_id = $matches[1];
    return $wpdb_hash->lookup($blog_id);
  }
}
$wpdb->add_callback('noblogs_db_callback');