Use explicit columns and avoid SELECT *

Change-Id: Ibde033784aee5adc13fae6f1d395d9464f54fefd
This commit is contained in:
Umherirrender 2019-03-02 21:25:33 +01:00
parent 8ce0cc171d
commit 1b5308ba81
6 changed files with 35 additions and 10 deletions

View file

@ -202,10 +202,17 @@ class MWEchoEmailBatch {
if ( $this->lastEvent ) {
$conds[] = 'eeb_event_id <= ' . intval( $this->lastEvent );
}
$fields = array_merge( EchoEvent::selectFields(), [
'eeb_id',
'eeb_user_id',
'eeb_event_priority',
'eeb_event_id',
'eeb_event_hash',
] );
$res = $dbr->select(
[ 'echo_email_batch', 'echo_event' ],
[ '*' ],
$fields,
$conds,
__METHOD__,
[

View file

@ -42,7 +42,7 @@ class EchoEventMapper extends EchoAbstractMapper {
public function fetchById( $id, $fromMaster = false ) {
$db = $fromMaster ? $this->dbFactory->getEchoDb( DB_MASTER ) : $this->dbFactory->getEchoDb( DB_REPLICA );
$row = $db->selectRow( 'echo_event', '*', [ 'event_id' => $id ], __METHOD__ );
$row = $db->selectRow( 'echo_event', EchoEvent::selectFields(), [ 'event_id' => $id ], __METHOD__ );
// If the row was not found, fall back on the master if it makes sense to do so
if ( !$row && !$fromMaster && $this->dbFactory->canRetryMaster() ) {
@ -91,7 +91,7 @@ class EchoEventMapper extends EchoAbstractMapper {
$dbr = $this->dbFactory->getEchoDb( DB_REPLICA );
$res = $dbr->select(
[ 'echo_event', 'echo_target_page' ],
[ '*' ],
EchoEvent::selectFields(),
[
'etp_page' => $pageId
],
@ -134,10 +134,11 @@ class EchoEventMapper extends EchoAbstractMapper {
*/
public function fetchUnreadByUserAndPage( User $user, $pageId ) {
$dbr = $this->dbFactory->getEchoDb( DB_REPLICA );
$fields = array_merge( EchoEvent::selectFields(), [ 'notification_timestamp' ] );
$res = $dbr->select(
[ 'echo_event', 'echo_notification', 'echo_target_page' ],
'*',
$fields,
[
'event_deleted' => 0,
'notification_user' => $user->getId(),

View file

@ -235,7 +235,7 @@ class EchoNotificationMapper extends EchoAbstractMapper {
$res = $dbr->select(
[ 'echo_notification', 'echo_event' ],
'*',
EchoNotification::selectFields(),
$conds,
__METHOD__,
[
@ -286,7 +286,7 @@ class EchoNotificationMapper extends EchoAbstractMapper {
$row = $dbr->selectRow(
[ 'echo_notification', 'echo_event' ],
[ '*' ],
EchoNotification::selectFields(),
[
'notification_user' => $user->getId(),
'notification_bundle_hash' => $bundleHash
@ -316,7 +316,7 @@ class EchoNotificationMapper extends EchoAbstractMapper {
$result = $dbr->select(
[ 'echo_notification', 'echo_event' ],
'*',
EchoNotification::selectFields(),
[
'notification_user' => $user->getId(),
'notification_event' => $eventIds
@ -350,7 +350,7 @@ class EchoNotificationMapper extends EchoAbstractMapper {
$dbr = $this->dbFactory->getEchoDb( DB_REPLICA );
$row = $dbr->selectRow(
[ 'echo_notification', 'echo_event' ],
[ '*' ],
EchoNotification::selectFields(),
[
'notification_user' => $user->getId(),
'event_deleted' => 0,

View file

@ -304,4 +304,21 @@ class EchoNotification extends EchoAbstractEntity implements Bundleable {
public function getSortingKey() {
return ( $this->isRead() ? '0' : '1' ) . '_' . $this->getTimestamp();
}
/**
* Return the list of fields that should be selected to create
* a new event with EchoNotification::newFromRow
* @return string[]
*/
public static function selectFields() {
return array_merge( EchoEvent::selectFields(), [
'notification_event',
'notification_user',
'notification_timestamp',
'notification_read_timestamp',
'notification_bundle_base',
'notification_bundle_hash',
'notification_bundle_display_hash',
] );
}
}

View file

@ -24,7 +24,7 @@ class NotificationPager extends ReverseChronologicalPager {
return [
'tables' => [ 'echo_notification', 'echo_event' ],
'fields' => '*',
'fields' => EchoNotification::selectFields(),
'conds' => [
'notification_user' => $this->getUser()->getId(),
'event_type' => $eventTypes,

View file

@ -83,7 +83,7 @@ class EchoTalkPageFunctionalTest extends ApiTestCase {
* @return \stdClass[] All events in db sorted from oldest to newest
*/
protected function fetchAllEvents() {
$res = $this->dbr->select( 'echo_event', [ '*' ], [], __METHOD__, [ 'ORDER BY' => 'event_id ASC' ] );
$res = $this->dbr->select( 'echo_event', EchoEvent::selectFields(), [], __METHOD__, [ 'ORDER BY' => 'event_id ASC' ] );
return iterator_to_array( $res );
}