Matthias Mullie has uploaded a new change for review.
https://gerrit.wikimedia.org/r/56387
Change subject: Fix cache issues
......................................................................
Fix cache issues
* Purge caches after adding a log note (otherwise this change was not being
picked up)
* Re-cache right away to avoid another user reads (& caches) data from a lagged
db slave
* Fix incorrect memc keys in purge script
Change-Id: I3d7a308dab24f5fc364ed2eb371efc3651c8e356
---
M ArticleFeedbackv5.activity.php
M api/ApiAddFlagNoteArticleFeedbackv5.php
M api/ApiFlagFeedbackArticleFeedbackv5.php
M maintenance/purgeCache.php
M modules/jquery.articleFeedbackv5/jquery.articleFeedbackv5.special.js
5 files changed, 91 insertions(+), 31 deletions(-)
git pull
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ArticleFeedbackv5
refs/changes/87/56387/1
diff --git a/ArticleFeedbackv5.activity.php b/ArticleFeedbackv5.activity.php
index 7102aa4..1292839 100644
--- a/ArticleFeedbackv5.activity.php
+++ b/ArticleFeedbackv5.activity.php
@@ -181,6 +181,25 @@
if ( $logId !== null ) {
// update log count in cache
static::incrementActivityCount( $itemId, $type );
+
+ $feedback = ArticleFeedbackv5Model::get( $itemId,
$pageId );
+ if ( $feedback ) {
+ global $wgMemc;
+
+ /*
+ * While we're at it, since activity has
occurred, the editor activity
+ * data in cache may be out of date.
+ */
+ $key = wfMemcKey( get_called_class(),
'getLastEditorActivity', $feedback->aft_id );
+ $wgMemc->delete( $key );
+
+ /*
+ * Re-cache the editor activity right away.
Otherwise, it could happen that
+ * another user is reading the editor activity
from a lagged slave & that
+ * data gets cached.
+ */
+ $feedback->getLastEditorActivity();
+ }
}
return $logId;
@@ -323,11 +342,6 @@
if ( $count !== false ) {
$wgMemc->set( $key, $count + 1, 60 * 60 * 24 * 7 );
}
-
- // while we're at it, since activity has occured, the editor
activity
- // data in cache may be out of date
- $key = wfMemcKey( get_called_class(), 'getLastEditorActivity',
$feedbackId );
- $wgMemc->delete( $key );
}
/**
diff --git a/api/ApiAddFlagNoteArticleFeedbackv5.php
b/api/ApiAddFlagNoteArticleFeedbackv5.php
index d1f6ab6..d149656 100644
--- a/api/ApiAddFlagNoteArticleFeedbackv5.php
+++ b/api/ApiAddFlagNoteArticleFeedbackv5.php
@@ -37,6 +37,8 @@
$logId = $params['logid'];
$action = $params['flagtype'];
$notes = $params['note'];
+ $feedbackId = $params['feedbackid'];
+ $pageId = $params['pageid'];
// update log entry in database
$dbw = ArticleFeedbackv5Utils::getDB( DB_MASTER );
@@ -52,10 +54,36 @@
'log_user' => $wgUser->getId(),
)
);
+
+ /**
+ * ManualLogEntry will have written to database. To
make sure that subsequent
+ * reads are up-to-date, I'll set a flag to know that
we've written data, so
+ * DB_MASTER will be queried.
+ */
+ ArticleFeedbackv5Utils::$written = true;
}
if ( $affected > 0 ) {
$results['result'] = 'Success';
+
+ $feedback = ArticleFeedbackv5Model::get( $feedbackId,
$pageId );
+ if ( $feedback ) {
+ global $wgMemc;
+
+ /*
+ * While we're at it, since activity has
occurred, the editor activity
+ * data in cache may be out of date.
+ */
+ $key = wfMemcKey( 'ArticleFeedbackv5Activity',
'getLastEditorActivity', $feedback->aft_id );
+ $wgMemc->delete( $key );
+
+ /*
+ * Re-cache the editor activity right away.
Otherwise, it could happen that
+ * another user is reading the editor activity
from a lagged slave & that
+ * data gets cached.
+ */
+ $feedback->getLastEditorActivity();
+ }
} else {
$results['result'] = 'Error';
}
@@ -76,7 +104,7 @@
*/
public function getAllowedParams() {
return array(
- 'logid' => array(
+ 'logid' => array(
ApiBase::PARAM_REQUIRED => true,
ApiBase::PARAM_TYPE => 'integer',
ApiBase::PARAM_MIN => 1
@@ -89,6 +117,16 @@
ApiBase::PARAM_REQUIRED => true,
ApiBase::PARAM_TYPE => 'string'
),
+ 'pageid' => array(
+ ApiBase::PARAM_REQUIRED => true,
+ ApiBase::PARAM_ISMULTI => false,
+ ApiBase::PARAM_TYPE => 'integer'
+ ),
+ 'feedbackid' => array(
+ ApiBase::PARAM_REQUIRED => true,
+ ApiBase::PARAM_ISMULTI => false,
+ ApiBase::PARAM_TYPE => 'string'
+ ),
);
}
@@ -99,8 +137,11 @@
*/
public function getParamDescription() {
return array(
- 'logid' => 'Log ID to update',
+ 'logid' => 'Log ID to update',
+ 'flagtype' => 'Type of flag to apply',
'note' => 'Information on why the feedback activity
occurred',
+ 'pageid' => 'PageID of feedback',
+ 'feedbackid' => 'FeedbackID to flag',
);
}
diff --git a/api/ApiFlagFeedbackArticleFeedbackv5.php
b/api/ApiFlagFeedbackArticleFeedbackv5.php
index 2fcb736..9dec424 100644
--- a/api/ApiFlagFeedbackArticleFeedbackv5.php
+++ b/api/ApiFlagFeedbackArticleFeedbackv5.php
@@ -79,7 +79,7 @@
*/
public function getAllowedParams() {
return array(
- 'pageid' => array(
+ 'pageid' => array(
ApiBase::PARAM_REQUIRED => true,
ApiBase::PARAM_ISMULTI => false,
ApiBase::PARAM_TYPE => 'integer'
@@ -89,7 +89,7 @@
ApiBase::PARAM_ISMULTI => false,
ApiBase::PARAM_TYPE => 'string'
),
- 'flagtype' => array(
+ 'flagtype' => array(
ApiBase::PARAM_REQUIRED => true,
ApiBase::PARAM_ISMULTI => false,
ApiBase::PARAM_TYPE => array_keys(
ArticleFeedbackv5Activity::$actions ),
@@ -119,12 +119,12 @@
*/
public function getParamDescription() {
return array(
- 'pageid' => 'PageID of feedback',
- 'feedbackid' => 'FeedbackID to flag',
- 'type' => 'Type of flag to apply',
- 'note' => 'Information on why the feedback
activity occurred',
- 'toggle' => 'The flag is being toggled atomically,
only useful for (un)helpful',
- 'source' => 'The origin of the flag: article
(page), central (feedback page), watchlist (page), permalink',
+ 'pageid' => 'PageID of feedback',
+ 'feedbackid' => 'FeedbackID to flag',
+ 'flagtype' => 'Type of flag to apply',
+ 'note' => 'Information on why the feedback activity
occurred',
+ 'toggle' => 'The flag is being toggled atomically, only
useful for (un)helpful',
+ 'source' => 'The origin of the flag: article (page),
central (feedback page), watchlist (page), permalink',
);
}
diff --git a/maintenance/purgeCache.php b/maintenance/purgeCache.php
index ec554d8..f4cb6bc 100644
--- a/maintenance/purgeCache.php
+++ b/maintenance/purgeCache.php
@@ -59,7 +59,7 @@
}
// feedback last editor activity
- $key = wfMemcKey( get_called_class(), 'getLastEditorActivity',
$object->aft_id );
+ $key = wfMemcKey( 'ArticleFeedbackv5Activity',
'getLastEditorActivity', $object->aft_id );
$wgMemc->delete( $key );
}
@@ -74,7 +74,7 @@
$class = $this->getClass();
// clear page found percentage
- $key = wfMemcKey( get_called_class(), 'getCountFound', $shard );
+ $key = wfMemcKey( $class, 'getCountFound', $shard );
$class::getCache()->delete( $key );
}
}
diff --git
a/modules/jquery.articleFeedbackv5/jquery.articleFeedbackv5.special.js
b/modules/jquery.articleFeedbackv5/jquery.articleFeedbackv5.special.js
index d7cf945..f38461c 100644
--- a/modules/jquery.articleFeedbackv5/jquery.articleFeedbackv5.special.js
+++ b/modules/jquery.articleFeedbackv5/jquery.articleFeedbackv5.special.js
@@ -408,6 +408,7 @@
} else {
var $container = $( '#' +
$.articleFeedbackv5special.currentPanelHostId ).closest(
'.articleFeedbackv5-feedback' );
var id = $container.data( 'id' );
+ var pageId = $container.data( 'pageid' );
var $noteLink = $container.find(
'#articleFeedbackv5-note-link-' + id );
var logId = $noteLink.data( 'log-id' );
@@ -415,6 +416,7 @@
$.articleFeedbackv5special.addNote(
id,
+ pageId,
logId,
action,
$(
'#articleFeedbackv5-noteflyover-note' ).attr( 'value' )
@@ -748,12 +750,13 @@
/**
* Updates the previous flag with a textual comment about it
*
- * @param id int the feedback id
- * @param logId int the log id
- * @param action string original action
- * @param note string note for action (default empty)
+ * @param feedbackId int the feedback id
+ * @param pageId int the page id
+ * @param logId int the log id
+ * @param action string original action
+ * @param note string note for action
(default empty)
*/
- $.articleFeedbackv5special.addNote = function ( id, logId, action, note
) {
+ $.articleFeedbackv5special.addNote = function ( feedbackId, pageId,
logId, action, note ) {
// note should be filled out or there's no point in firing this
request
if ( !note ) {
return false;
@@ -766,24 +769,26 @@
// Merge request data and options objects (flat)
var requestData = {
- 'logid' : logId,
- 'note' : note,
- 'flagtype' : action,
- 'format' : 'json',
- 'action' : 'articlefeedbackv5-add-flag-note'
+ 'feedbackid' : feedbackId,
+ 'pageid' : pageId,
+ 'logid' : logId,
+ 'note' : note,
+ 'flagtype' : action,
+ 'format' : 'json',
+ 'action' : 'articlefeedbackv5-add-flag-note'
};
$.ajax( {
- 'url' : $.articleFeedbackv5special.apiUrl,
- 'type' : 'POST',
+ 'url' : $.articleFeedbackv5special.apiUrl,
+ 'type' : 'POST',
'dataType': 'json',
- 'data' : requestData,
+ 'data' : requestData,
'success': function ( data ) {
if ( 'articlefeedbackv5-add-flag-note' in data
) {
if ( 'result' in
data['articlefeedbackv5-add-flag-note'] ) {
if (
data['articlefeedbackv5-add-flag-note'].result == 'Success' ) {
// remove "add note"
link
- $(
'#articleFeedbackv5-note-link-' + id ).remove();
+ $(
'#articleFeedbackv5-note-link-' + feedbackId ).remove();
// re-enable ajax
flagging
$.articleFeedbackv5special.listControls.disabled = false;
--
To view, visit https://gerrit.wikimedia.org/r/56387
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I3d7a308dab24f5fc364ed2eb371efc3651c8e356
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/ArticleFeedbackv5
Gerrit-Branch: master
Gerrit-Owner: Matthias Mullie <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits