Nikerabbit has uploaded a new change for review. https://gerrit.wikimedia.org/r/204224
Change subject: Optimize draft content loading query ...................................................................... Optimize draft content loading query The old query was incorrect and caused memory limit to be exceeded and thus preventing access to many non-small drafts due to multiplication effect. Changed the method which is only used once to only return draft content and optimized the query. For more details see T94402. Bug: T94402 Change-Id: I1437f37e779888a62578d88f56d47ceb3663c884 --- M api/ApiQueryContentTranslation.php M includes/Translator.php 2 files changed, 18 insertions(+), 20 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ContentTranslation refs/changes/24/204224/1 diff --git a/api/ApiQueryContentTranslation.php b/api/ApiQueryContentTranslation.php index 799f449..183bf13 100644 --- a/api/ApiQueryContentTranslation.php +++ b/api/ApiQueryContentTranslation.php @@ -44,12 +44,12 @@ } if ( $params['translationid'] ) { $translator = new ContentTranslation\Translator( $user ); - $translation = $translator->getTranslation( $params['translationid'] ); - if ( $translation !== null ) { + $draftContent = $translator->getDraftContent( $params['translationid'] ); + if ( $draftContent !== null ) { $result->addValue( array( 'query', 'contenttranslation' ), 'translation', - $translation->translation + $draftContent ); } else { $this->dieUsage( 'Draft does not exist', $params['translationid'] ); diff --git a/includes/Translator.php b/includes/Translator.php index 499c057..28f281e 100644 --- a/includes/Translator.php +++ b/includes/Translator.php @@ -37,30 +37,28 @@ } /** - * Get a translation by translation id for the translator - * @return Translation + * Get draft html. + * + * @param int $draftId + * @return string|null Draft html or null if draft doesn't exist or belongs + * to different translator. */ - public function getTranslation( $translationId ) { + public function getDraftContent( $draftId ) { $dbr = Database::getConnection( DB_SLAVE ); - $rows = $dbr->select( - array( 'cx_translations', 'cx_translators', 'cx_drafts' ), - '*', + + // Find the translation in ownership table and join the content + $draftContent = $dbr->selectField( + array( 'cx_translators', 'cx_drafts' ), + 'draft_content', array( - 'translator_translation_id' => $translationId, - 'draft_id' => $translationId, - 'translator_user_id' => $this->getGlobalUserId() + 'translator_user_id' => $this->getGlobalUserId(), + 'translator_translation_id' => $draftId, + 'translator_translation_id = draft_id', ), __METHOD__ ); - $result = array(); - foreach ( $rows as $row ) { - $result[] = Translation::newFromRow( $row ); - } - if ( count( $result ) > 0 ) { - return $result[0]; - } - return null; + return is_string( $draftContent ) ? $draftContent : null; } /** -- To view, visit https://gerrit.wikimedia.org/r/204224 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I1437f37e779888a62578d88f56d47ceb3663c884 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/ContentTranslation Gerrit-Branch: master Gerrit-Owner: Nikerabbit <niklas.laxst...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits