db-hash.php 449 Bytes
Newer Older
root's avatar
root committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<?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');