forked from Automattic/vip-go-mu-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
schema.php
32 lines (27 loc) · 905 Bytes
/
schema.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<?php
/**
* Plugin Name: VIP Schema
* Description: Provides VIP-specific database schema customizations.
* Author: Automattic
* License: GPL version 2 or later - http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
*/
namespace Automattic\VIP\Schema;
add_filter( 'dbdelta_create_queries', function( $queries ) {
global $wpdb;
foreach ( $queries as $k => $q ) {
// Replace meta_key index with one that indexes meta_value as well
if ( preg_match( '|CREATE TABLE ([^ ]*)|', $q, $matches ) && $wpdb->postmeta === $matches[1] ) {
$queries[ $k ] = str_replace(
'KEY meta_key (meta_key(191))',
sprintf( 'KEY %s', get_postmeta_key_value_index() ),
$q
);
}
}
return $queries;
});
function get_postmeta_key_value_index() {
// 191 for meta_key is max set by core.
// 100 for meta_value is arbitrary-ish.
return '`vip_meta_key_value` (`meta_key`(191), `meta_value`(100))';
}