mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-12-18 02:40:50 +00:00
Use explicit columns and avoid SELECT *
Change-Id: Ibde033784aee5adc13fae6f1d395d9464f54fefd
This commit is contained in:
parent
8ce0cc171d
commit
1b5308ba81
|
@ -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__,
|
||||
[
|
||||
|
|
|
@ -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(),
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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',
|
||||
] );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue