r113104 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r113103‎ | r113104 | r113105 >
Date:23:10, 5 March 2012
Author:emsmith
Status:resolved (Comments)
Tags:
Comment:
bug 34090 - follow up to rr111472 part 3 - totally redo the continue functionality with lots more code
Modified paths:
  • /trunk/extensions/ArticleFeedbackv5/api/ApiViewActivityArticleFeedbackv5.php (modified) (history)
  • /trunk/extensions/ArticleFeedbackv5/modules/jquery.articleFeedbackv5/jquery.articleFeedbackv5.special.js (modified) (history)

Diff [purge]

Index: trunk/extensions/ArticleFeedbackv5/modules/jquery.articleFeedbackv5/jquery.articleFeedbackv5.special.js
@@ -650,8 +650,8 @@
651651 'format': 'json',
652652 'aafeedbackid': id,
653653 };
654 - if( continueId > 0 ) {
655 - data['aacontinue'] = continueId;
 654+ if( continueId ) {
 655+ data['aacontinue'] = continueId;
656656 }
657657 $.ajax( {
658658 'url': $.articleFeedbackv5special.apiUrl,
@@ -659,15 +659,15 @@
660660 'dataType': 'json',
661661 'data': data,
662662 'success': function( data ) {
663 - if( 0 == continueId ) {
 663+ if( data['articlefeedbackv5-view-activity'].hasHeader ) {
664664 $( '#articlefeedbackv5-activity-log' ).html( data['articlefeedbackv5-view-activity'].activity );
665665 } else {
666666 $( '#articlefeedbackv5-activity-log' )
667667 .find( '.articleFeedbackv5-activity-more' ).replaceWith( data['articlefeedbackv5-view-activity'].activity );
668668 }
669 - if( data['articlefeedbackv5-view-activity'].continue ) {
 669+ if( data['query-continue']['articlefeedbackv5-view-activity'] ) {
670670 $( '#articlefeedbackv5-activity-log' ).find( '.articleFeedbackv5-activity-more' )
671 - .attr( 'rel', data['articlefeedbackv5-view-activity'].continue )
 671+ .attr( 'rel', data['query-continue']['articlefeedbackv5-view-activity'].aacontinue )
672672 .click( function( e ) {
673673 $.articleFeedbackv5special.loadActivityLog(
674674 $( '#' + $.articleFeedbackv5special.currentPanelHostId ).closest( '.articleFeedbackv5-feedback' ).attr( 'rel' ),
Index: trunk/extensions/ArticleFeedbackv5/api/ApiViewActivityArticleFeedbackv5.php
@@ -45,6 +45,7 @@
4646 $feedbackId = $params['feedbackid'];
4747 $limit = $params['limit'];
4848 $continue = $params['continue'];
 49+ $result = $this->getResult();
4950
5051 // fetch our activity database information
5152 $feedback = $this->fetchFeedback( $feedbackId );
@@ -62,16 +63,14 @@
6364
6465 // get our activities
6566 $activities = $this->fetchActivity( $title, $feedbackId, $limit, $continue);
66 - $old_continue = $continue;
6767
68 - // overwrite previous continue for new value
69 - $continue = null;
70 -
7168 // generate our html
7269 $html = '';
7370
74 - // only do this if continue < 1
75 - if ($old_continue < 1) {
 71+ // only do this if continue is not null
 72+ if ( !$continue ) {
 73+ $result->addValue( $this->getModuleName(), 'hasHeader', true );
 74+
7675 // <div class="articleFeedbackv5-activity-pane">
7776 $html .= Html::openElement( 'div', array(
7877 'class' => 'articleFeedbackv5-activity-pane'
@@ -124,6 +123,8 @@
125124 ) );
126125 }
127126
 127+ $count = 0;
 128+
128129 // divs of activity items
129130 foreach($activities as $item) {
130131
@@ -132,6 +133,13 @@
133134 continue;
134135 }
135136
 137+ $count++;
 138+
 139+ // figure out if we have more if we have another row past our limit
 140+ if($count > $limit) {
 141+ break;
 142+ }
 143+
136144 // <div class="articleFeedbackv5-activity-item">
137145 $html .= Html::openElement( 'div', array(
138146 'class' => 'articleFeedbackv5-activity-item'
@@ -155,16 +163,10 @@
156164
157165 // </div> for class="articleFeedbackv5-activity-item"
158166 $html .= Html::closeElement( 'div' );
159 -
160 - // the last item's log_id should be the continue;
161 - $continue = $item->log_id;
162167 }
163168
164 - // figure out if we have more based on our new continue value
165 - $more = $this->fetchHasMore($title, $feedbackId, $continue);
166 -
167169 //optional <a href="#" class="articleFeedbackv5-activity-more">Show more Activity</a>
168 - if ($more) {
 170+ if ($count > $limit) {
169171 $html .= Html::element( 'a', array(
170172 'class' => "articleFeedbackv5-activity-more",
171173 'href' => '#',
@@ -175,50 +177,16 @@
176178 $html .= Html::closeElement( 'div' );
177179
178180 // finally add our generated html data
179 - $result = $this->getResult();
180181 $result->addValue( $this->getModuleName(), 'limit', $limit );
181182 $result->addValue( $this->getModuleName(), 'activity', $html );
182183
183184 // continue only goes in if it's not empty
184 - if ($continue > 0) {
185 - $result->addValue( $this->getModuleName(), 'continue', $continue );
 185+ if ($count > $limit) {
 186+ $this->setContinueEnumParameter( 'continue', $this->getContinue( $item ) );
186187 }
187 -
188 - // more only goes in if there are more entries
189 - if ($more) {
190 - $result->addValue( $this->getModuleName(), 'more', $more );
191 - }
192188 }
193189
194190 /**
195 - * Sees if there are additional activity rows to view
196 - *
197 - * @param string $title the title of the page
198 - * @param int $feedbackId identifier for the feedback item we are fetching activity for
199 - * @param mixed $continue used for offsets
200 - * @return bool true if there are more rows, or false
201 - */
202 - protected function fetchHasMore( $title, $feedbackId, $continue = null ) {
203 - $dbr = wfGetDB( DB_SLAVE );
204 -
205 - $feedback = $dbr->selectField(
206 - array( 'logging' ),
207 - array( 'log_id'),
208 - array(
209 - 'log_type' => 'articlefeedbackv5',
210 - 'log_title' => "ArticleFeedbackv5/$title/$feedbackId",
211 - 'log_id < ' . intval($continue)
212 - ),
213 - __METHOD__,
214 - array(
215 - 'LIMIT' => 1
216 - )
217 - );
218 -
219 - return ( (bool) $feedback );
220 - }
221 -
222 - /**
223191 * Gets some base feedback information
224192 *
225193 * @param int $feedbackId identifier for the feedback item we are fetching activity for
@@ -264,9 +232,7 @@
265233 'log_title' => "ArticleFeedbackv5/$title/$feedbackId"
266234 );
267235
268 - if ( null !== $continue ) {
269 - $where[] = 'log_id < ' . intval($continue);
270 - }
 236+ $where = $this->applyContinue( $continue, $where );
271237
272238 $dbr = wfGetDB( DB_SLAVE );
273239 $activity = $dbr->select(
@@ -281,8 +247,8 @@
282248 $where,
283249 __METHOD__,
284250 array(
285 - 'LIMIT' => $limit,
286 - 'ORDER BY' => 'log_id DESC'
 251+ 'LIMIT' => $limit + 1,
 252+ 'ORDER BY' => 'log_timestamp DESC, log_id ASC'
287253 )
288254 );
289255
@@ -376,5 +342,34 @@
377343 );
378344 return $element;
379345 }
 346+
 347+ /**
 348+ * Creates a timestamp/id tuple for continue
 349+ */
 350+ protected function getContinue( $row ) {
 351+ $ts = wfTimestamp( TS_MW, $row->log_timestamp );
 352+ return "$ts|{$row->log_id}";
 353+ }
 354+
 355+ /**
 356+ * gets timestamp and id pair for continue
 357+ */
 358+ protected function applyContinue( $continue, $where ) {
 359+ if ( !$continue ) {
 360+ return $where;
 361+ }
 362+
 363+ $vals = explode( '|', $continue, 3 );
 364+ if ( count( $vals ) !== 2 ) {
 365+ $this->dieUsage( 'Invalid continue param. You should pass the original value returned by the previous query', 'badcontinue' );
 366+ }
 367+
 368+ $db = $this->getDB();
 369+ $ts = $db->addQuotes( $db->timestamp( $vals[0] ) );
 370+ $id = intval( $vals[1] );
 371+ $where[] = '(log_id = ' . $id . ' AND log_timestamp = ' . $ts . ') OR log_timestamp < ' . $ts;
 372+
 373+ return $where;
 374+ }
380375 }
381376

Follow-up revisions

RevisionCommit summaryAuthorDate
r113159bug 34090 - follow up to rr111472 part 4 and follow up to r111596 (same issue...emsmith17:37, 6 March 2012
r113160bug 34090 - follow up to rr111472 part 5 plural and number format action countemsmith17:48, 6 March 2012
r113161bug 34090 - follow up to rr111472 part 6 last of lego messagesemsmith17:53, 6 March 2012
r113163bug 34090 - two additional configuration settings (help url and admin user ur...emsmith18:02, 6 March 2012
r113193bug 34090 - followup to r113104 - only sort by timestamp (sorting by log id w...emsmith22:56, 6 March 2012
r113228bug 34090 - followup to r113160emsmith14:05, 7 March 2012
r113247bug 34090 - db issue, remove one of the sorts from the query, use the ids arr...emsmith16:52, 7 March 2012
r113269bug 34090 - followup to r113247emsmith19:01, 7 March 2012
r113273bug 34090 - add javascript level hiding on request oversight IF autohidden is...emsmith19:22, 7 March 2012
r113287bug 34090 - usernames and formatted timestamps into red lines for hidden/over...emsmith20:22, 7 March 2012
r113311bug 34090 - fixing the username bugs - apparently using the data- stuff with ...emsmith22:34, 7 March 2012
r113317bug 34090 - js and css voodoo to make the element with the red lines appear a...emsmith23:01, 7 March 2012
r113370bug 34090 - make different titles for masking appear if it's been hidden or o...emsmith16:43, 8 March 2012
r113371bug 34090 - fixes for oversighter view for hide/oversight panelsemsmith17:51, 8 March 2012
r113383bug 34090 - not entirely necessary, but keeps $2 from showing up in hiders pa...emsmith19:25, 8 March 2012
r113384bug 34090 - fix for double red line issues when hiding an oversighted post ha...emsmith19:28, 8 March 2012
r113390bug 34090 - adding translation for "automatic hider" useremsmith19:44, 8 March 2012
r113392bug 34090 - followup to r113287 - adjusted localization documentationemsmith20:03, 8 March 2012
r113393bug 34090 - followup to r113370 - adjusted localization documentationemsmith20:05, 8 March 2012

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r111211bug 34090 - Added a log namespace and log types for the Article Feedback v5 e...emsmith22:53, 10 February 2012
r111472bug 34090 - Added an additional column in the main feedback table to keep a c...emsmith19:14, 14 February 2012
r111474bug 34090 - remove a todo - take the note from the flag submission and save i...emsmith19:57, 14 February 2012
r111552bug 34090 - split activity notes into their own config for maximum length (th...emsmith16:07, 15 February 2012
r111557bug 34090 - changed structure of the link classes and ids per the following f...emsmith16:47, 15 February 2012
r111570bug 34090 - request oversight is now a counter - so you can request/unrequest...emsmith19:53, 15 February 2012
r111573bug 34090 - removed the "header" portion of the html generation from the acti...emsmith20:18, 15 February 2012
r111645bug 34090 - updated the filter count update script to get requested oversight...emsmith15:45, 16 February 2012
r112038bug 34090 - added additional counts for filters including unhidden, undeleted...emsmith20:28, 21 February 2012
r112039bug 34090 - fixed issue noted : if $feedback is false return nothing - not th...emsmith20:50, 21 February 2012
r112041bug 34090 - kill the -1 issue by never letting it get below 0emsmith21:08, 21 February 2012
r112115bug 34090 - no code changes, just fixing/adding keyword svn propertiesemsmith16:31, 22 February 2012
r112119bug 34090 - cast the naughty column so it can be signed, the greatest still k...emsmith16:57, 22 February 2012
r112142bug 34090 - toggle for atomic un/helpful changing (and elimination of an extr...emsmith20:37, 22 February 2012
r112147bug 34090 - note to self, watch the copy and paste errors...emsmith21:01, 22 February 2012
r112149bug 34090 - no upper limit, only lower limit - we can't get any worse then 0emsmith21:21, 22 February 2012
r112154bug 34090 - quick and dirty helper script to get missing documentation keysemsmith21:57, 22 February 2012
r112156bug 34090 - only send the activity header if continue < 1, make the more div ...emsmith22:14, 22 February 2012
r112161bug 34090 - fix limit and use old continue to determine if we do the headeremsmith23:15, 22 February 2012
r112218bug 34090 - make sure the name are right for hidden/unhidden logging (argh)emsmith16:44, 23 February 2012
r112225bug 34090 - unhidden and unoversight logic adjustmentsemsmith18:06, 23 February 2012
r112228bug 34090 - fix filter - needsoversight are always autohiddenemsmith19:16, 23 February 2012
r112230bug 34090 - let's try this again - needsoversight and declined will have hidd...emsmith19:38, 23 February 2012
r112232bug 34090 - hide and show shouldn't fiddle with oversight counts or declined ...emsmith19:48, 23 February 2012
r112599bug 34090 - follow up to r111211 - rename things to make them "less confusin...emsmith14:43, 28 February 2012
r112603bug 34090 - Add the logging of automated hide/show errors by the "Article Fee...emsmith15:21, 28 February 2012
r112604bug 34090 - can't believe there were no permissions checks in this - only del...emsmith15:38, 28 February 2012
r112610bug 34090 - change all sql updates to use escaping except for explicitly comm...emsmith16:22, 28 February 2012
r112611bug 34090 - take out implicit show and add returning user that hid/oversighte...emsmith17:02, 28 February 2012
r112627bug 34090 - follow up to r112599 - change to use getText since it's going int...emsmith18:53, 28 February 2012
r112825bug 34090 - insert custom attributes (sigh) for the user and formatted timest...emsmith18:14, 1 March 2012
r112830bug 34090 - follow up to r111474 - use truncate for choppingemsmith19:42, 1 March 2012
r113052bug 34090 - remaining backend feature in requirements, oversight email genera...emsmith18:04, 5 March 2012
r113062bug 34090 - follow up to r110520 1. change index 2. default of null for conti...emsmith18:54, 5 March 2012
r113073bug 34090 - follow up to r111472 part 1 - change to use getDbKey, check for b...emsmith19:48, 5 March 2012
r113082bug 34090 - follow up to r111471 - changed to use text()emsmith20:42, 5 March 2012
r113083bug 34090 - follow up to rr111472 part 2 - only use log_id for orderingemsmith20:48, 5 March 2012

Comments

#Comment by Catrope (talk | contribs)   22:33, 6 March 2012
+ 'ORDER BY' => 'log_timestamp DESC, log_id ASC'

You cannot mix DESC and ASC sorting, that will definitely be slow. In my CR of r111472 I recommended that you drop timestamp sorting and sort only by IS.

+ $where[] = '(log_id = ' . $id . ' AND log_timestamp = ' . $ts . ') OR log_timestamp < ' . $ts;

This looks wrong. It should be (log_id = $id AND log_timestamp <= $ts) OR log_timestamp < $ts (<= versus =).

OK otherwise.

Status & tagging log