From 4ffebd80f2205da4bc96d05f5101b2ea72895e5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartosz=20Dziewo=C5=84ski?= Date: Tue, 16 Aug 2022 20:11:05 +0200 Subject: [PATCH] Add config option to enable/disable permalinks backend From in-person code review with Amir: using tableExists() is a bad idea, because the table might not consistently exists on all replicas. It's better to have a config option despite the inconvenience. Bug: T315353 Change-Id: I728759634c454c0dcbdc4603c15cab60415c7c03 --- extension.json | 4 ++++ includes/ThreadItemStore.php | 13 +++++-------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/extension.json b/extension.json index 3f094d927..36729fb04 100644 --- a/extension.json +++ b/extension.json @@ -620,6 +620,10 @@ "value": "default", "description": "Override availability of DiscussionTools visual enhancements's reply buttons sub-feature. 'default', 'available', or 'unavailable'." }, + "DiscussionToolsEnablePermalinksBackend": { + "value": true, + "description": "Enable the permalinks backend. Do not enable this unless the database tables exist." + }, "DiscussionToolsAutoTopicSubEditor": { "value": "discussiontoolsapi", "description": "Editor which triggers automatic topic subscriptions. Either 'discussiontoolsapi' for edits made using DiscussionTools' API (e.g. reply and new topic tools), or 'any' for any editor." diff --git a/includes/ThreadItemStore.php b/includes/ThreadItemStore.php index 195c88ea3..e2d7d3d71 100644 --- a/includes/ThreadItemStore.php +++ b/includes/ThreadItemStore.php @@ -16,9 +16,9 @@ use MWTimestamp; use ReadOnlyMode; use stdClass; use TitleFormatter; +use Wikimedia\Rdbms\IDatabase; use Wikimedia\Rdbms\ILBFactory; use Wikimedia\Rdbms\ILoadBalancer; -use Wikimedia\Rdbms\IMaintainableDatabase; use Wikimedia\Rdbms\IResultWrapper; use Wikimedia\Rdbms\SelectQueryBuilder; @@ -81,19 +81,16 @@ class ThreadItemStore { * @return bool */ private function isDisabled(): bool { - static $tablesCreated = null; - if ( $tablesCreated === null ) { - $tablesCreated = $this->getConnectionRef( DB_REPLICA )->tableExists( 'discussiontools_items', __METHOD__ ); - } - return !$tablesCreated; + $dtConfig = $this->configFactory->makeConfig( 'discussiontools' ); + return !$dtConfig->get( 'DiscussionToolsEnablePermalinksBackend' ); } /** * @param int $dbIndex DB_PRIMARY or DB_REPLICA * - * @return IMaintainableDatabase + * @return IDatabase */ - private function getConnectionRef( int $dbIndex ): IMaintainableDatabase { + private function getConnectionRef( int $dbIndex ): IDatabase { return $this->loadBalancer->getConnectionRef( $dbIndex, [ 'watchlist' ] ); }