Merge "Use upsert() in ProfilerOutputDb"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Tue, 18 Nov 2014 20:47:34 +0000 (20:47 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Tue, 18 Nov 2014 20:47:34 +0000 (20:47 +0000)
1  2 
includes/profiler/output/ProfilerOutputDb.php

@@@ -35,7 -35,7 +35,7 @@@ class ProfilerOutputDb extends Profiler
                return !wfReadOnly();
        }
  
 -      protected function logStandardData( array $stats ) {
 +      public function log( array $stats ) {
                global $wgProfilePerHost;
  
                if ( $wgProfilePerHost ) {
                                $timeSum = $timeSum >= 0 ? $timeSum : 0;
                                $memorySum = $memorySum >= 0 ? $memorySum : 0;
  
-                               $dbw->update( 'profiling',
+                               $dbw->upsert( 'profiling',
+                                       array(
+                                               'pf_name' => $name,
+                                               'pf_count' => $eventCount,
+                                               'pf_time' => $timeSum,
+                                               'pf_memory' => $memorySum,
+                                               'pf_server' => $pfhost
+                                       ),
+                                       array( array( 'pf_name', 'pf_server' ) ),
                                        array(
                                                "pf_count=pf_count+{$eventCount}",
                                                "pf_time=pf_time+{$timeSum}",
                                                "pf_memory=pf_memory+{$memorySum}",
                                        ),
-                                       array(
-                                               'pf_name' => $name,
-                                               'pf_server' => $pfhost,
-                                       ),
-                                       __METHOD__ );
-                               $rc = $dbw->affectedRows();
-                               if ( $rc == 0 ) {
-                                       $dbw->insert( 'profiling',
-                                               array(
-                                                       'pf_name' => $name,
-                                                       'pf_count' => $eventCount,
-                                                       'pf_time' => $timeSum,
-                                                       'pf_memory' => $memorySum,
-                                                       'pf_server' => $pfhost
-                                               ),
-                                               __METHOD__,
-                                               array( 'IGNORE' )
-                                       );
-                               }
-                               // When we upgrade to mysql 4.1, the insert+update
-                               // can be merged into just a insert with this construct added:
-                               //     "ON DUPLICATE KEY UPDATE ".
-                               //     "pf_count=pf_count + VALUES(pf_count), ".
-                               //     "pf_time=pf_time + VALUES(pf_time)";
+                                       __METHOD__
+                               );
                        }
                        if ( $useTrx ) {
                                $dbw->endAtomic( __METHOD__ );