* (bug 27333) Fix repetitive last-seen time queries on page history
authorBrion Vibber <brion@users.mediawiki.org>
Sat, 12 Feb 2011 01:10:48 +0000 (01:10 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Sat, 12 Feb 2011 01:10:48 +0000 (01:10 +0000)
Title::getNotificationTimestamp() is called for every line in HistoryPager, to compare against the revision's timestamp to determine if it's a new edit since the viewer's last visit to the page.
The function kept an internal cache within the Title object to avoid having to make the query over and over in this situation, but in the case that it returns null, the cached entry would be accidentally ignored on the next round due to use of isset() to check for the array entry. (Most of the time it's great, but if the value of the key actually *is* null, isset() returns false.) Switched to array_key_exists(), which doesn't have this false negative. Now only one query gets issued for this on a history page, even if the answer is null.

includes/Title.php

index dfadd7a..a0b36e8 100644 (file)
@@ -3870,7 +3870,8 @@ class Title {
                }
                // Check cache first
                $uid = $user->getId();
-               if ( isset( $this->mNotificationTimestamp[$uid] ) ) {
+               // avoid isset here, as it'll return false for null entries
+               if ( array_key_exists( $uid, $this->mNotificationTimestamp ) ) {
                        return $this->mNotificationTimestamp[$uid];
                }
                if ( !$uid || !$wgShowUpdatedMarker ) {