r108561 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r108560‎ | r108561 | r108562 >
Date:23:31, 10 January 2012
Author:bsitu
Status:ok (Comments)
Tags:
Comment:
followup to -r108556 - make the maintenance script to process in batchsize at a time and add default 0 for mbf_latest_response
Modified paths:
  • /trunk/extensions/MoodBar/sql/MoodBar.sql (modified) (history)
  • /trunk/extensions/MoodBar/sql/mbf_latest_response.sql (modified) (history)
  • /trunk/extensions/MoodBar/updateMoodBarFeedback.php (modified) (history)

Diff [purge]

Index: trunk/extensions/MoodBar/updateMoodBarFeedback.php
@@ -31,25 +31,39 @@
3232 $this->output( "Updating mbf_latest_response in moodbar_feedback table...\n" );
3333
3434 // Grab the feedback record with mbf_latest_response = 0
35 - $res = $db->select( array( 'moodbar_feedback', 'moodbar_feedback_response' ),
36 - array( 'MAX(mbfr_id) AS latest_mbfr_id', 'mbf_id' ),
37 - array( 'mbf_id=mbfr_mbf_id', 'mbf_latest_response' => 0 ),
38 - __METHOD__,
39 - array( 'GROUP BY' => 'mbfr_mbf_id' )
40 - );
41 - $count = 0;
42 - foreach ( $res as $row ) {
43 - $count++;
44 - if ( $count % 100 == 0 ) {
45 - $this->output( $count . "\n" );
46 - wfWaitForSlaves();
 35+ $lastMbfId = $totalCount = 0;
 36+ $batchSize = $count = 100;
 37+
 38+ while ( $batchSize == $count ) {
 39+ $count = 0;
 40+ $res = $db->select( array( 'moodbar_feedback', 'moodbar_feedback_response' ),
 41+ array( 'MAX(mbfr_id) AS latest_mbfr_id', 'mbf_id' ),
 42+ array( 'mbf_id=mbfr_mbf_id', 'mbf_latest_response' => 0, 'mbf_id > ' . $lastMbfId ),
 43+ __METHOD__,
 44+ array( 'ORDER BY' => 'mbf_id', 'GROUP BY' => 'mbf_id', "LIMIT $batchSize" )
 45+ );
 46+
 47+ foreach ( $res as $row ) {
 48+ $count++;
 49+ $mbfrId = intval( $row->latest_mbfr_id );
 50+ $mbfId = intval( $row->mbf_id );
 51+
 52+ $db->update( 'moodbar_feedback',
 53+ array( 'mbf_latest_response' => $mbfrId ),
 54+ array( 'mbf_id' => $mbfId ),
 55+ __METHOD__ );
 56+
 57+ $lastMbfId = $mbfId;
4758 }
48 - $db->update( 'moodbar_feedback',
49 - array( 'mbf_latest_response' => intval( $row->latest_mbfr_id ) ),
50 - array( 'mbf_id' => intval( $row->mbf_id ) ),
51 - __METHOD__ );
 59+
 60+ $totalCount = $totalCount + $count;
 61+
 62+ $this->output( $count . "\n" );
 63+ wfWaitForSlaves();
 64+
5265 }
53 - $this->output( "Done, $count rows updated.\n" );
 66+
 67+ $this->output( "Done, $totalCount rows updated.\n" );
5468 return true;
5569 }
5670 }
Index: trunk/extensions/MoodBar/sql/MoodBar.sql
@@ -16,7 +16,7 @@
1717 mbf_comment varchar(255) binary,
1818
1919 -- Latest response id for this feedback
20 - mbf_latest_response int unsigned NOT NULL,
 20+ mbf_latest_response int unsigned NOT NULL default 0,
2121 -- Options and context
2222 -- Whether or not the feedback item is hidden
2323 -- 0 = No; 255 = Yes (other values reserved for partial hiding)
Index: trunk/extensions/MoodBar/sql/mbf_latest_response.sql
@@ -1,2 +1,2 @@
2 -ALTER TABLE /*_*/moodbar_feedback ADD COLUMN mbf_latest_response int unsigned NOT NULL;
 2+ALTER TABLE /*_*/moodbar_feedback ADD COLUMN mbf_latest_response int unsigned NOT NULL default 0;
33 CREATE INDEX /*i*/mbf_latest_response ON /*_*/moodbar_feedback (mbf_latest_response);

Follow-up revisions

RevisionCommit summaryAuthorDate
r108575followup to -r108561 - code consistencybsitu00:29, 11 January 2012

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r108556followup to -r108187 - Introducing new field mbf_latest_response for latest f...bsitu22:42, 10 January 2012

Comments

#Comment by Catrope (talk | contribs)   00:19, 11 January 2012
+						array( 'ORDER BY' => 'mbf_id', 'GROUP BY' => 'mbf_id', "LIMIT $batchSize" )

You can use 'LIMIT' => $batchSize as well.

+			$totalCount = $totalCount + $count;

A shortcut for this is $totalCount += $count;

Marking OK.

Status & tagging log