mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/DiscussionTools
synced 2024-11-23 16:06:53 +00:00
Find comment: limit DB query for page comments, use a custom exception
Follow-up to b7af4e87f5
Bug: T374598
Change-Id: Ibc958f84991198ebb616cf41258e70968353f7fe
This commit is contained in:
parent
b2e1dda6a7
commit
9492fcc1f8
|
@ -8,7 +8,6 @@ use ApiUsageException;
|
|||
use MediaWiki\Extension\DiscussionTools\ThreadItem\DatabaseThreadItem;
|
||||
use MediaWiki\Title\Title;
|
||||
use MediaWiki\Title\TitleFormatter;
|
||||
use Wikimedia\NormalizedException\NormalizedException;
|
||||
use Wikimedia\ParamValidator\ParamValidator;
|
||||
|
||||
class ApiDiscussionToolsFindComment extends ApiBase {
|
||||
|
@ -66,7 +65,7 @@ class ApiDiscussionToolsFindComment extends ApiBase {
|
|||
$byHeading = $this->threadItemStore->findNewestRevisionsByHeading(
|
||||
$heading, $articleId, $title->getTitleValue()
|
||||
);
|
||||
} catch ( NormalizedException $e ) {
|
||||
} catch ( PageNeverHadThreadsException $e ) {
|
||||
$this->dieWithError( [ 'apierror-discussiontools-findcomment-pagenevertalk' ] );
|
||||
}
|
||||
foreach ( $byHeading as $item ) {
|
||||
|
|
8
includes/PageNeverHadThreadsException.php
Normal file
8
includes/PageNeverHadThreadsException.php
Normal file
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace MediaWiki\Extension\DiscussionTools;
|
||||
|
||||
use Wikimedia\NormalizedException\NormalizedException;
|
||||
|
||||
class PageNeverHadThreadsException extends NormalizedException {
|
||||
}
|
|
@ -268,12 +268,13 @@ class ThreadItemStore {
|
|||
) ) )
|
||||
// On the specified page ID
|
||||
->where( [ 'rev_page' => $articleId ] )
|
||||
->field( 'itid_itemid' );
|
||||
->field( 'itid_itemid' )
|
||||
->limit( 1 );
|
||||
|
||||
// Check there is only one result in the sub-query
|
||||
$itemIds = $anyItemsInPageHistoryQueryBuilder->fetchFieldValues();
|
||||
if ( count( $itemIds ) === 0 ) {
|
||||
throw new NormalizedException(
|
||||
throw new PageNeverHadThreadsException(
|
||||
"Page {page} has never contained any discussions",
|
||||
[ 'page' => $articleId ]
|
||||
);
|
||||
|
|
Loading…
Reference in a new issue