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) {
function noblogs_get_backend_for_blog($blog_id) {
global $wpdb;
global $r2db_hash_map;
global $wpdb_reverse_backend_map;
// Compatibility shim between old/new r2db.
$hash_map = $r2db_hash_map;
......@@ -36,16 +37,9 @@ function noblogs_get_backend_for_blog($blog_id) {
$hash_map = $wpdb->hash_map;
}
// Create a temporary hash object just to load the backends
// (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 the 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.
$result = array();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment