From 3f4e41a24ec250c46f99d1a151dfaf0f9f4b1767 Mon Sep 17 00:00:00 2001 From: Reedy Date: Sat, 28 Apr 2012 00:59:59 +0100 Subject: [PATCH] Noticed while looking at $wgShowUpdatedMarker related database queries, queries not using index order at all. Fixed up Title.php at line 4313: array( 'wl_namespace' => $this->getNamespace(), 'wl_title' => $this->getDBkey(), 'wl_user' => $user->getId() ), In UserMailer.php at line 438: array( 'wl_title' => $title->getDBkey(), 'wl_namespace' => $title->getNamespace(), 'wl_user != ' . intval( $editor->getID() ), 'wl_notificationtimestamp IS NULL', ) And line 455: array( /* WHERE */ 'wl_title' => $title->getDBkey(), 'wl_namespace' => $title->getNamespace(), 'wl_user' => $watchers ) CREATE TABLE /*_*/watchlist ( -- Key to user.user_id wl_user int unsigned NOT NULL, -- Key to page_namespace/page_title -- Note that users may watch pages which do not exist yet, -- or existed in the past but have been deleted. wl_namespace int NOT NULL default 0, wl_title varchar(255) binary NOT NULL default '', -- Timestamp when user was last sent a notification e-mail; -- cleared when the user visits the page. wl_notificationtimestamp varbinary(14) ) /*$wgDBTableOptions*/; CREATE UNIQUE INDEX /*i*/wl_user ON /*_*/watchlist (wl_user, wl_namespace, wl_title); CREATE INDEX /*i*/namespace_title ON /*_*/watchlist (wl_namespace, wl_title); Change-Id: I633c009b4a1c614b966c69f042f94c2056e03784 --- includes/Title.php | 5 +++-- includes/UserMailer.php | 8 ++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/includes/Title.php b/includes/Title.php index 6764f8f8d1..1c5c832c0c 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -4310,9 +4310,10 @@ class Title { $dbr = wfGetDB( DB_SLAVE ); $this->mNotificationTimestamp[$uid] = $dbr->selectField( 'watchlist', 'wl_notificationtimestamp', - array( 'wl_namespace' => $this->getNamespace(), + array( + 'wl_user' => $user->getId(), + 'wl_namespace' => $this->getNamespace(), 'wl_title' => $this->getDBkey(), - 'wl_user' => $user->getId() ), __METHOD__ ); diff --git a/includes/UserMailer.php b/includes/UserMailer.php index e0b8d01abb..36da6fbd97 100644 --- a/includes/UserMailer.php +++ b/includes/UserMailer.php @@ -436,9 +436,9 @@ class EmailNotification { $res = $dbw->select( array( 'watchlist' ), array( 'wl_user' ), array( - 'wl_title' => $title->getDBkey(), - 'wl_namespace' => $title->getNamespace(), 'wl_user != ' . intval( $editor->getID() ), + 'wl_namespace' => $title->getNamespace(), + 'wl_title' => $title->getDBkey(), 'wl_notificationtimestamp IS NULL', ), __METHOD__ ); @@ -453,9 +453,9 @@ class EmailNotification { array( /* SET */ 'wl_notificationtimestamp' => $dbw->timestamp( $timestamp ) ), array( /* WHERE */ - 'wl_title' => $title->getDBkey(), + 'wl_user' => $watchers, 'wl_namespace' => $title->getNamespace(), - 'wl_user' => $watchers + 'wl_title' => $title->getDBkey(), ), __METHOD__ ); $dbw->commit( __METHOD__ ); -- 2.20.1