Skip to content
Snippets Groups Projects
Commit c92e382f authored by ale's avatar ale
Browse files

Do not instantiate a second Flexihash just to find the backend name

Fixes issue #3.
parent 2db59e49
No related branches found
No related tags found
No related merge requests found
...@@ -29,6 +29,7 @@ function noblogs_get_blog($blogname) { ...@@ -29,6 +29,7 @@ function noblogs_get_blog($blogname) {
function noblogs_get_backend_for_blog($blog_id) { function noblogs_get_backend_for_blog($blog_id) {
global $wpdb; global $wpdb;
global $r2db_hash_map; global $r2db_hash_map;
global $wpdb_reverse_backend_map;
// Compatibility shim between old/new r2db. // Compatibility shim between old/new r2db.
$hash_map = $r2db_hash_map; $hash_map = $r2db_hash_map;
...@@ -36,16 +37,9 @@ function noblogs_get_backend_for_blog($blog_id) { ...@@ -36,16 +37,9 @@ function noblogs_get_backend_for_blog($blog_id) {
$hash_map = $wpdb->hash_map; $hash_map = $wpdb->hash_map;
} }
// Create a temporary hash object just to load the backends // Lookup the blog ID.
// (we cannot use the map in $wpdb because it doesn't have the
// backend array anymore).
$hashmap = new Flexihash(null, R2DB_FLEXIHASH_REPLICAS);
$reversemap = noblogs_load_backends($hashmap);
// Lookup the blog ID using the $wpdb hash just to be safe (though
// we should get an identical result using $hashmap).
$lookup = $hash_map->lookup($blog_id); $lookup = $hash_map->lookup($blog_id);
$backend = $reversemap[$lookup]; $backend = $wpdb_reverse_backend_map[$lookup];
// Be nice and split the database host into 'host' and 'port' elements. // Be nice and split the database host into 'host' and 'port' elements.
$result = array(); $result = array();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment