mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/AbuseFilter.git
synced 2024-11-23 21:53:35 +00:00
Avoid array to object cast in filterToDatabaseRow
Both callers immediately call get_object_vars to cast it back to array. Avoid this roundtrip. Change-Id: I6525d76f8a03a4d28c2b50b580c539affe98064f
This commit is contained in:
parent
f9a2d4cf6c
commit
7ae2060b27
|
@ -9,7 +9,6 @@ use MediaWiki\Extension\AbuseFilter\Filter\Filter;
|
|||
use MediaWiki\Extension\AbuseFilter\Special\SpecialAbuseFilter;
|
||||
use MediaWiki\User\UserIdentity;
|
||||
use Status;
|
||||
use stdClass;
|
||||
use User;
|
||||
use Wikimedia\Rdbms\ILoadBalancer;
|
||||
|
||||
|
@ -128,7 +127,7 @@ class FilterStore {
|
|||
bool $wasGlobal
|
||||
): array {
|
||||
$dbw = $this->loadBalancer->getConnectionRef( DB_PRIMARY );
|
||||
$newRow = get_object_vars( $this->filterToDatabaseRow( $newFilter ) );
|
||||
$newRow = $this->filterToDatabaseRow( $newFilter );
|
||||
|
||||
// Set last modifier.
|
||||
$newRow['af_timestamp'] = $dbw->timestamp();
|
||||
|
@ -249,11 +248,11 @@ class FilterStore {
|
|||
/**
|
||||
* @todo Perhaps add validation to ensure no null values remained.
|
||||
* @param Filter $filter
|
||||
* @return stdClass
|
||||
* @return array
|
||||
*/
|
||||
private function filterToDatabaseRow( Filter $filter ): stdClass {
|
||||
private function filterToDatabaseRow( Filter $filter ): array {
|
||||
// T67807: integer 1's & 0's might be better understood than booleans
|
||||
return (object)[
|
||||
return [
|
||||
'af_id' => $filter->getID(),
|
||||
'af_pattern' => $filter->getRules(),
|
||||
'af_public_comments' => $filter->getName(),
|
||||
|
|
|
@ -48,7 +48,7 @@ class FilterStoreTest extends MediaWikiIntegrationTestCase {
|
|||
$filterStore = TestingAccessWrapper::newFromObject( AbuseFilterServices::getFilterStore() );
|
||||
wfGetDB( DB_PRIMARY )->insert(
|
||||
'abuse_filter',
|
||||
get_object_vars( $filterStore->filterToDatabaseRow( $filter ) ),
|
||||
$filterStore->filterToDatabaseRow( $filter ),
|
||||
__METHOD__
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue