Skip to content

Conversation

@vncloudsco
Copy link

error handling in report #166 By excluding the admin from using the features in the administration, ensuring data is always accurate and timely, users will still be able to navigate as usual.

@sonarqubecloud
Copy link

@justinmaurerdotdev
Copy link

I'm not sure everyone is going to want to bypass replicas in the admin. In some setups, replicas could accept reads or could contain specific parts of the database. We've solved this in our db-config.php with this (probably still not fully optimized) setup:

if (defined( 'WP_CLI' ) && WP_CLI || defined( 'WP_ADMIN' ) && WP_ADMIN) {
	/**
	 * If we're in the WP CLI, we want to prevent cache/replica sync race conditions,
	 * so we will only use the master db here
	 */
	$wpdb->add_database( array(
		'host'     => DB_HOST,
		'user'     => DB_USER,
		'password' => DB_PASSWORD,
		'name'     => DB_NAME,
		'write'    => 1,
		'read'     => 1,
	) );
} else {
	/**
	 * Front end reads all come from the replica. All writes go to the master.
	 */
	$wpdb->add_database( array(
		'host'     => DB_HOST,
		'user'     => DB_USER,
		'password' => DB_PASSWORD,
		'name'     => DB_NAME,
		'write'    => 1, 
		'read'     => 0,
	) );
	
	$wpdb->add_database(array(
		'host'     => REPLICA_DB_HOST,
		'user'     => REPLICA_DB_USER,
		'password' => REPLICA_DB_PASSWORD,
		'name'     => REPLICA_DB_NAME,
		'write'    => 0, // replica doesn't take write queries
		'read'     => 1, // ... but it does take read queries
	));
}

@vncloudsco
Copy link
Author

@justinmaurerdotdev i know it's extreme to ignore it but really the new post feature can't work so just leave this part alone, this merger may not be accepted but it's a good solution to the problem of not being able to access the new post creation page

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants