Merge "Move edit-user-talk to messages"

This commit is contained in:
jenkins-bot 2015-09-05 00:04:52 +00:00 committed by Gerrit Code Review
commit 43604b5922
6 changed files with 15 additions and 104 deletions

View file

@ -301,7 +301,7 @@ $wgEchoNotifications = array(
'secondary-link' => array( 'message' => 'notification-link-text-view-changes', 'destination' => 'diff' ),
'category' => 'edit-user-talk',
'group' => 'interactive',
'section' => 'alert',
'section' => 'message',
'bundle' => array( 'web' => true, 'email' => false ),
'formatter-class' => 'EchoEditUserTalkFormatter',
'title-message' => 'notification-edit-talk-page2',

View file

@ -1,9 +1,3 @@
/*!
* Grunt file
*
* @package Flow
*/
/*jshint node:true */
module.exports = function ( grunt ) {
grunt.loadNpmTasks( 'grunt-contrib-csslint' );

View file

@ -125,7 +125,7 @@
"apihelp-echomarkseen-param-type": "Type of notifications to mark as seen: 'alert', 'message' or 'all'.",
"apihelp-query+notifications-description": "Get notifications waiting for the current user.",
"apihelp-query+notifications-param-prop": "Details to request.",
"apihelp-query+notifications-param-sections": "The notification sections to query.",
"apihelp-query+notifications-param-sections": "The notification sections to query (i.e. some combination of 'alert' and 'message').",
"apihelp-query+notifications-param-groupbysection": "Whether to group the result by section. Each section is fetched separately if set.",
"apihelp-query+notifications-param-format": "If specified, notifications will be returned formatted this way.",
"apihelp-query+notifications-param-limit": "The maximum number of notifications to return.",

View file

@ -35,14 +35,6 @@ class MWEchoNotifUser {
*/
private $targetPageMapper;
/**
* Whether to check cache for section status
*/
static $sectionStatusCheckCache = array (
EchoAttributeManager::ALERT => false,
EchoAttributeManager::MESSAGE => true
);
/**
* Usually client code doesn't need to initialize the object directly
* because it could be obtained from factory method newFromUser()
@ -85,80 +77,6 @@ class MWEchoNotifUser {
);
}
/**
* Check whether should trigger a query to fetch data for a section when making
* such request. This method normally should return true for all section.
* For some sections, it's better to save the result in cache and check before
* triggering a query. Flow is in very limited deployment, Most *users would
* not have flow notifications, it's better to save *this status in cache
* to save a query. In addition, Flow notification is far less than other
* notifications for most users at this moment. Querying could be expensive
* in extreme cases
* @param string $section
* @return boolean
*/
public function shouldQuerySectionData( $section ) {
if ( !self::$sectionStatusCheckCache[$section] ) {
return true;
}
$cacheVal = $this->cache->get( $this->sectionStatusCacheKey( $section ) );
// '1' means should query
// '0' means should not query
// false means no cache and should query
if ( $cacheVal !== '0' ) {
return true;
} else {
return false;
}
}
/**
* Set section data status into cache, '1' means there is data for the section,
* '0' means there is no data for this section
* @param string $section
* @param int $num
*/
public function setSectionStatusCache( $section, $num ) {
if ( !self::$sectionStatusCheckCache[$section] ) {
return;
}
$key = $this->sectionStatusCacheKey( $section );
// Set cache for 5 days
if ( $num > 0 ) {
$this->cache->set( $key, '1', 432000 );
} else {
$this->cache->set( $key, '0', 432000 );
}
}
/**
* Clear section data cache for the section
* @param string
*/
public function clearSectionStatusCache( $section ) {
if ( !self::$sectionStatusCheckCache[$section] ) {
return;
}
$this->cache->delete(
$this->sectionStatusCacheKey( $section )
);
}
/**
* Get the section data status cache key
* @param string $section
* @return string
*/
protected function sectionStatusCacheKey( $section ) {
global $wgEchoConfig;
return wfMemcKey(
'echo-notification-section-exist',
$section,
$this->mUser->getId(),
$wgEchoConfig['version']
);
}
/**
* Clear talk page notification when users visit their talk pages. This
* only resets if the notification count is less than max notification
@ -420,6 +338,15 @@ class MWEchoNotifUser {
$this->targetPageMapper->deleteByUserEvents( $this->mUser, $eventIds );
// Update notification count in cache
$this->resetNotificationCount( DB_MASTER );
// After this 'mark read', is there any unread edit-user-talk
// remaining? If not, we should clear the newtalk flag.
if ( $this->mUser->getNewtalk() ) {
$unreadEditUserTalk = $this->notifMapper->fetchUnreadByUser( $this->mUser, 1, array( 'edit-user-talk' ), DB_MASTER );
if ( count( $unreadEditUserTalk ) === 0 ) {
$this->mUser->setNewtalk( false );
}
}
}
return $res;
}

View file

@ -70,7 +70,7 @@ class ApiEchoNotifications extends ApiQueryBase {
/**
* Internal method for getting the property 'list' data for individual section
* @param User $user
* @param string $section
* @param string $section 'alert' or 'message'
* @param int $limit
* @param string $continue
* @param string $format
@ -81,9 +81,8 @@ class ApiEchoNotifications extends ApiQueryBase {
$notifUser = MWEchoNotifUser::newFromUser( $user );
$attributeManager = EchoAttributeManager::newFromGlobalVars();
$sectionEvents = $attributeManager->getUserEnabledEventsbySections( $user, 'web', array( $section ) );
// Some section like 'message' only has flow notifications, which most wikis and
// users don't have, we should skip the query in such case
if ( !$sectionEvents || !$notifUser->shouldQuerySectionData( $section ) ) {
if ( !$sectionEvents ) {
$result = array(
'list' => array(),
'continue' => null
@ -92,12 +91,6 @@ class ApiEchoNotifications extends ApiQueryBase {
$result = $this->getPropList(
$user, $sectionEvents, $limit, $continue, $format, $unreadFirst
);
// If events exist for applicable section we should set the section status
// in cache to check whether a query should be triggered in later request.
// This is mostly for users who don't have 'message' notifications
if ( $sectionEvents ) {
$notifUser->setSectionStatusCache( $section, count( $result['list'] ) );
}
}
return $result;
}
@ -265,7 +258,7 @@ class ApiEchoNotifications extends ApiQueryBase {
public function getParamDescription() {
return array(
'prop' => 'Details to request.',
'sections' => 'The notification sections to query.',
'sections' => 'The notification sections to query (i.e. some combination of \'alert\' and \'message\').',
'groupbysection' => 'Whether to group the result by section, each section is fetched separately if set',
'format' => 'If specified, notifications will be returned formatted this way.',
'index' => 'If specified, a list of notification IDs, in order, will be returned.',

View file

@ -166,9 +166,6 @@ class EchoNotification extends EchoAbstractEntity {
$notifMapper->insert( $this );
// Clear applicable section status from cache upon new notification creation
$notifUser->clearSectionStatusCache( $section );
if ( $event->getType() === 'edit-user-talk' ) {
$notifUser->flagCacheWithNewTalkNotification();
}