mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Gadgets
synced 2024-11-15 03:23:51 +00:00
Avoid validating gadget definition content multiple times on save
The validation appears to be occurring 4 times: 1. JsonContentHandler->preSaveTransform --> GadgetDefinitionContent->isValid 2. GadgetHooks::onEditFilterMergedContent --> GadgetDefinitionContent->validate 3. ContentHandler->validateSave --> GadgetDefinitionContent->isValid 4. RevisionStore->checkContent ---> GadgetDefinitionContent->isValid Caching the validation result reduces it down to 2. (Validation in GadgetHooks::onEditFilterMergedContent is to provide a more useful error message than what ContentHandler gives – which is just "Invalid content data".) Change-Id: I026751b7e9b111b4f0bb9ab5fa0e9737a0385b07
This commit is contained in:
parent
43a6221fc9
commit
bded600e36
|
@ -22,6 +22,12 @@
|
|||
|
||||
class GadgetDefinitionContent extends JsonContent {
|
||||
|
||||
/** @var Status|null Cached validation result */
|
||||
private $validation;
|
||||
|
||||
/**
|
||||
* @param string $text
|
||||
*/
|
||||
public function __construct( $text ) {
|
||||
parent::__construct( $text, 'GadgetDefinition' );
|
||||
}
|
||||
|
@ -47,12 +53,16 @@ class GadgetDefinitionContent extends JsonContent {
|
|||
* @return Status
|
||||
*/
|
||||
public function validate() {
|
||||
if ( !parent::isValid() ) {
|
||||
return $this->getData();
|
||||
// Cache the validation result to avoid re-computations
|
||||
if ( !$this->validation ) {
|
||||
if ( !parent::isValid() ) {
|
||||
$this->validation = $this->getData();
|
||||
} else {
|
||||
$validator = new GadgetDefinitionValidator();
|
||||
$this->validation = $validator->validate( $this->getAssocArray() );
|
||||
}
|
||||
}
|
||||
|
||||
$validator = new GadgetDefinitionValidator();
|
||||
return $validator->validate( $this->getAssocArray() );
|
||||
return $this->validation;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue