r106234 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r106233‎ | r106234 | r106235 >
Date:19:30, 14 December 2011
Author:kaldari
Status:ok
Tags:
Comment:
follow-up to r105641 - better db syncing, using primary keys, etc
Modified paths:
  • /trunk/extensions/ContributionReporting/PopulateFundraisingStatistics.php (modified) (history)
  • /trunk/extensions/ContributionReporting/patches/public-reporting-summaries.sql (modified) (history)

Diff [purge]

Index: trunk/extensions/ContributionReporting/PopulateFundraisingStatistics.php
@@ -47,21 +47,6 @@
4848 }
4949
5050 /**
51 - * Wait for all the slave database servers to sync up with the master
52 - */
53 - public function syncDBs() {
54 - // FIXME: Copied from populateAFRevisions.php, which coppied from updateCollation.php, should be centralized somewhere
55 - $lb = wfGetLB();
56 - // bug 27975 - Don't try to wait for slaves if there are none
57 - // Prevents permission error when getting master position
58 - if ( $lb->getServerCount() > 1 ) {
59 - $dbw = $lb->getConnection( DB_MASTER );
60 - $pos = $dbw->getMasterPos();
61 - $lb->waitForAll( $pos );
62 - }
63 - }
64 -
65 - /**
6651 * Bootstrap this maintenance script
6752 *
6853 * Performs operations necessary for this maintenance script to run which
@@ -72,16 +57,19 @@
7358 * Set user-specified operations to perform
7459 */
7560 $operations = explode( ',', $this->getOption( 'op' ) );
76 - // check sanity of specified operations
 61+ // Check sanity of specified operations
7762 if ( !$this->checkOperations( $operations ) ) {
7863 $this->error( 'Invalid operation specified.', true );
7964 } else {
8065 $this->operations = $operations;
8166 }
8267
83 - // set db objects
 68+ // Set database objects
8469 $this->dbr = wfGetDB( DB_SLAVE );
8570 $this->dbw = wfGetDB( DB_MASTER );
 71+
 72+ // Set timezone to UTC (contribution data will always be in UTC)
 73+ date_default_timezone_set( 'UTC' );
8674 }
8775
8876 /**
@@ -129,8 +117,8 @@
130118 $this->output( "Writing data to public_reporting_days...\n" );
131119
132120 $conditions = array(
133 - 'converted_amount >= ' . $egFundraiserStatisticsMinimum,
134 - 'converted_amount <= ' . $egFundraiserStatisticsMaximum
 121+ 'converted_amount >= ' . intval( $egFundraiserStatisticsMinimum ),
 122+ 'converted_amount <= ' . intval( $egFundraiserStatisticsMaximum )
135123 );
136124
137125 // Get the data for a fundraiser
@@ -168,8 +156,8 @@
169157 $res = $this->dbw->delete( 'public_reporting_days', array( 1 ) );
170158 // Insert the new totals
171159 $res = $this->dbw->insert( 'public_reporting_days', $insertArray, __METHOD__ );
172 - // Sync the databases
173 - $this->syncDBs();
 160+ // Wait for the databases to sync
 161+ wfWaitForSlaves();
174162 }
175163
176164 $lag = time() - $begin;
@@ -228,8 +216,8 @@
229217 $res = $this->dbw->delete( 'public_reporting_fundraisers', array( 1 ) );
230218 // Insert the new totals
231219 $res = $this->dbw->insert( 'public_reporting_fundraisers', $insertArray, __METHOD__ );
232 - // Sync the databases
233 - $this->syncDBs();
 220+ // Wait for the databases to sync
 221+ wfWaitForSlaves();
234222 }
235223 $lag = time() - $begin;
236224 $this->output( "Inserted " . $records . " rows. ($lag seconds)\n" );
@@ -294,8 +282,6 @@
295283 }
296284
297285 if ( $records > 0 ) {
298 - // Set timezone to UTC to match donation servers
299 - date_default_timezone_set( 'UTC' );
300286 // Empty the table of previous totals for this fundraiser
301287 $res = $this->dbw->delete(
302288 'public_reporting_days',
@@ -306,8 +292,8 @@
307293 );
308294 // Insert the new totals
309295 $res = $this->dbw->insert( 'public_reporting_days', $insertArray, __METHOD__ );
310 - // Sync the databases
311 - $this->syncDBs();
 296+ // Wait for the databases to sync
 297+ wfWaitForSlaves();
312298 }
313299
314300 $lag = time() - $begin;
Index: trunk/extensions/ContributionReporting/patches/public-reporting-summaries.sql
@@ -7,8 +7,8 @@
88 `prf_average` decimal(8,4) NOT NULL DEFAULT '0.0000',
99 `prf_maximum` decimal(11,4) NOT NULL DEFAULT '0.0000',
1010 `prf_insert_timestamp` int(10) NOT NULL,
 11+ PRIMARY KEY (prf_id)
1112 ) /*$wgDBTableOptions*/;
12 -CREATE UNIQUE INDEX /*i*/prf_id ON /*$wgDBprefix*/public_reporting_fundraisers (prf_id);
1313
1414 CREATE TABLE IF NOT EXISTS /*$wgDBprefix*/public_reporting_days (
1515 `prd_date` date NOT NULL,
@@ -17,5 +17,5 @@
1818 `prd_average` decimal(8,4) unsigned NOT NULL DEFAULT '0.0000',
1919 `prd_maximum` decimal(11,4) unsigned NOT NULL DEFAULT '0.0000',
2020 `prd_insert_timestamp` int(10) NOT NULL,
 21+ PRIMARY KEY (prd_date)
2122 ) /*$wgDBTableOptions*/;
22 -CREATE UNIQUE INDEX /*i*/prf_id ON /*$wgDBprefix*/public_reporting_days (prd_date);

Follow-up revisions

RevisionCommit summaryAuthorDate
r106696MFT r105145, r105454, r105641, r105657, r105659, r105757, r105916, r105965, r...awjrichards20:59, 19 December 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r105641an initial implementation of a stats summary system. not yet integrated into ...kaldari02:24, 9 December 2011

Status & tagging log