Skip to content
This repository was archived by the owner on Aug 26, 2025. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions src/Db.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
// TODO(maddog) Go through the whole extension and make sure DB access is
// principled and compatible with a load-balanced/clustered setup.
//
// In particular, we need to ensure that DB_MASTER is used (and
// In particular, we need to ensure that DB_PRIMARY is used (and
// used consistently) when it is needed, and not used when not.
// In addition to the choices we make in this file, other things
// that access the DB (e.g., User::idFromName()), won't
Expand Down Expand Up @@ -113,7 +113,7 @@ public static function ensureCurrentSchema() {
* @throws MWException if the lock could not be acquired.
*/
public static function acquireLockOnDiscourseId( int $discourse_id ) : void {
$dbw = wfGetDB( DB_MASTER );
$dbw = wfGetDB( DB_PRIMARY );
$key = self::LOCK_KEY_PREFIX . (string)($discourse_id);
$lock = $dbw->getScopedLockAndFlush( $key, __METHOD__, self::LOCK_TIMEOUT );

Expand Down Expand Up @@ -142,7 +142,7 @@ function () use ( $lock ) { ScopedCallback::consume( $lock ); },
* discourse_id, wiki_id, and wiki_username; otherwise, returns null.
*/
public static function lookupDiscourseId( int $discourseId ) : ?object {
$dbr = wfGetDB( DB_MASTER );
$dbr = wfGetDB( DB_PRIMARY );
$row = $dbr->selectRow(
// tables
[ 'dsc' => Schema::LINK_TABLE, 'u' => 'user' ],
Expand Down Expand Up @@ -181,7 +181,7 @@ public static function lookupDiscourseId( int $discourseId ) : ?object {
* @return ?int the associated Discourse id if $wikiId is known, else null
*/
public static function lookupDiscourseIdByWikiId( int $wikiId ) : ?int {
$dbr = wfGetDB( DB_MASTER );
$dbr = wfGetDB( DB_PRIMARY );
$row = $dbr->selectRow(
// tables
[ 'dsc' => Schema::LINK_TABLE ],
Expand Down Expand Up @@ -225,7 +225,7 @@ public static function findUserByEmail( string $email ) : ?object {
// TODO(maddog) What happens (and what should happen) if the email address
// is used by multiple wiki users? (e.g., selectRow() is
// here returning only one of potentially multiple rows.)
$dbr = wfGetDB( DB_MASTER );
$dbr = wfGetDB( DB_PRIMARY );
$row = $dbr->selectRow(
// tables
[ 'u' => 'user' ],
Expand Down Expand Up @@ -267,7 +267,7 @@ public static function findUserByUsername( string $username ) : ?object {
Util::debug( 'Username is empty string, skipping.' );
return null;
}
$dbr = wfGetDB( DB_MASTER );
$dbr = wfGetDB( DB_PRIMARY );
$row = $dbr->selectRow(
// tables
[ 'u' => 'user' ],
Expand Down Expand Up @@ -311,7 +311,7 @@ public static function updateIdLinkage( int $discourseId, int $wikiId )
: void {
Util::debug(
"Linking discourse-id '{$discourseId}' to wiki-id '{$wikiId}'." );
$dbw = wfGetDB( DB_MASTER );
$dbw = wfGetDB( DB_PRIMARY );
$dbw->upsert(
// table
Schema::LINK_TABLE,
Expand Down Expand Up @@ -374,7 +374,7 @@ public static function updateUserRecord( object $userRecord,
$discourseId = $userRecord->id;
$jsonUserBlob = Util::encodeObjectAsJson( $userRecord );

$dbw = wfGetDB( DB_MASTER );
$dbw = wfGetDB( DB_PRIMARY );
$dbw->upsert(
// table
Schema::USER_TABLE,
Expand Down Expand Up @@ -408,7 +408,7 @@ public static function updateUserRecord( object $userRecord,
public static function fetchUserRecord( int $discourseId ) : ?object {
Util::debug( "Fetching user record for discourse-id '{$discourseId}'" );

$dbr = wfGetDB( DB_MASTER );
$dbr = wfGetDB( DB_PRIMARY );
$row = $dbr->selectRow(
// tables
[ 'dsu' => Schema::USER_TABLE ],
Expand Down