Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
r2db
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Noblogs
r2db
Commits
7c857273
Commit
7c857273
authored
4 years ago
by
ale
Browse files
Options
Downloads
Patches
Plain Diff
Use our own global variable for the FlexiHash instance
Instead of using an attribute inside $wpdb.
parent
5b798c39
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
db-hash.php
+3
-3
3 additions, 3 deletions
db-hash.php
with
3 additions
and
3 deletions
db-hash.php
+
3
−
3
View file @
7c857273
...
...
@@ -3,17 +3,17 @@
require_once
(
dirname
(
__FILE__
)
.
'/flexihash.php'
);
require_once
(
ABSPATH
.
'wp-config.php'
);
$
wpdb
->
hash_map
=
new
Flexihash
(
null
,
R2DB_FLEXIHASH_REPLICAS
);
$
r2db_
hash_map
=
new
Flexihash
(
null
,
R2DB_FLEXIHASH_REPLICAS
);
/* Hashing function to map blogs to databases.
*
* Implements a consistent hashing scheme using Flexihash.
*/
function
noblogs_db_callback
(
$query
,
$wpdb
)
{
$wpdb_hash
=
$wpdb
->
hash_map
;
global
$r2db_
hash_map
;
if
(
preg_match
(
"/^
{
$wpdb
->
base_prefix
}
(\d+)_/"
,
$wpdb
->
table
,
$matches
))
{
$blog_id
=
$matches
[
1
];
return
$
wp
db_hash
->
lookup
(
$blog_id
);
return
$
r2
db_hash
_map
->
lookup
(
$blog_id
);
}
}
$wpdb
->
add_callback
(
'noblogs_db_callback'
);
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment