Added ss_images to site_stats, to replace the slow count(*) query in Parser.php.
authorTim Starling <tstarling@users.mediawiki.org>
Tue, 28 Mar 2006 05:09:33 +0000 (05:09 +0000)
committerTim Starling <tstarling@users.mediawiki.org>
Tue, 28 Mar 2006 05:09:33 +0000 (05:09 +0000)
includes/Image.php
includes/ImagePage.php
includes/Parser.php
includes/SpecialStatistics.php
languages/Messages.php
maintenance/archives/patch-ss_images.sql [new file with mode: 0644]
maintenance/mysql5/tables.sql
maintenance/tables.sql
maintenance/updaters.inc

index 96f8c5c..9d23e95 100644 (file)
@@ -1488,6 +1488,11 @@ class Image
                                        'img_name' => $this->name
                                ), $fname
                        );
+               } else {
+                       # This is a new image
+                       # Update the image count
+                       $site_stats = $dbw->tableName( 'site_stats' );
+                       $dbw->query( "UPDATE $site_stats SET ss_images=ss_images+1", $fname );
                }
 
                $article = new Article( $descTitle );
index 0e55156..98feeb4 100644 (file)
@@ -521,6 +521,14 @@ END
                                return;
                        }
                        $dbw->delete( 'image', array( 'img_name' => $image ) );
+
+                       if ( $dbw->affectedRows() ) {
+                               # Update site_stats
+                               $site_stats = $dbw->tableName( 'site_stats' );
+                               $dbw->query( "UPDATE $site_stats SET ss_images=ss_images-1", $fname );
+                       }
+                       
+
                        $res = $dbw->select( 'oldimage', array( 'oi_archive_name' ), array( 'oi_name' => $image ) );
 
                        # Purge archive URLs from the squid
@@ -552,7 +560,6 @@ END
                        /* Delete thumbnails and refresh image metadata cache */
                        $this->img->purgeCache();
 
-
                        $deleted = $image;
                }
 
index a846fc8..ac06185 100644 (file)
@@ -4119,14 +4119,14 @@ function wfNumberOfArticles() {
  * Return the number of files
  */
 function wfNumberOfFiles() {
-       $fname = 'Parser::wfNumberOfFiles';
+       $fname = 'wfNumberOfFiles';
 
        wfProfileIn( $fname );
        $dbr =& wfGetDB( DB_SLAVE );
-       $res = $dbr->selectField('image', 'COUNT(*)', array(), $fname );
+       $numImages = $dbr->selectField('site_stats', 'ss_images', array(), $fname );
        wfProfileOut( $fname );
 
-       return $res;
+       return $numImages;
 }
 
 /**
index f5583fe..6ff3338 100644 (file)
@@ -21,6 +21,7 @@ function wfSpecialStatistics() {
        $views = $row->ss_total_views;
        $edits = $row->ss_total_edits;
        $good = $row->ss_good_articles;
+       $images = $row->ss_images;
 
        # This code is somewhat schema-agnostic, because I'm changing it in a minor release -- TS
        if ( isset( $row->ss_total_pages ) && $row->ss_total_pages == -1 ) {
@@ -50,12 +51,11 @@ function wfSpecialStatistics() {
 
        $admins = $dbr->selectField( 'user_groups', 'COUNT(*)', array( 'ug_group' => 'sysop' ), $fname );
        $numJobs = $dbr->selectField( 'job', 'COUNT(*)', '', $fname );
-       $numFiles = $dbr->selectField( 'image', 'COUNT(*)', '', $fname );
 
        if ($action == 'raw') {
                $wgOut->disable();
                header( 'Pragma: nocache' );
-               echo "total=$total;good=$good;views=$views;edits=$edits;users=$users;admins=$admins;files=$numFiles\n";
+               echo "total=$total;good=$good;views=$views;edits=$edits;users=$users;admins=$admins;images=$images\n";
                return;
        } else {
                $text = '==' . wfMsg( 'sitestats' ) . "==\n" ;
@@ -67,7 +67,7 @@ function wfSpecialStatistics() {
                        $wgLang->formatNum( sprintf( '%.2f', $total ? $edits / $total : 0 ) ),
                        $wgLang->formatNum( sprintf( '%.2f', $edits ? $views / $edits : 0 ) ),
                        $wgLang->formatNum( $numJobs ),
-                       $wgLang->formatNum( $numFiles )
+                       $wgLang->formatNum( $images )
                );
 
                $text .= "\n==" . wfMsg( 'userstats' ) . "==\n";
index 55233b2..3baa824 100644 (file)
@@ -917,7 +917,9 @@ this old version, (rev) = revert to this old version.
 This includes \"talk\" pages, pages about {{SITENAME}}, minimal \"stub\"
 pages, redirects, and others that probably don't qualify as content pages.
 Excluding those, there are '''$2''' pages that are probably legitimate
-content pages. We have '''$8''' files uploaded.
+content pages. 
+
+'''$8''' files have been uploaded.
 
 There have been a total of '''$3''' page views, and '''$4''' page edits
 since the wiki was setup.
diff --git a/maintenance/archives/patch-ss_images.sql b/maintenance/archives/patch-ss_images.sql
new file mode 100644 (file)
index 0000000..2a9519b
--- /dev/null
@@ -0,0 +1,5 @@
+-- More statistics, for version 1.6
+
+ALTER TABLE /*$wgDBprefix*/site_stats ADD ss_images int(10) default '0';
+SELECT @images := COUNT(*) FROM /*$wgDBprefix*/image;
+UPDATE site_stats SET ss_images=@images;
index 2f0999c..c2b9bc9 100644 (file)
@@ -520,6 +520,9 @@ CREATE TABLE /*$wgDBprefix*/site_stats (
   -- Deprecated, no longer updated as of 1.5
   ss_admins int(10) default '-1',
 
+  -- Number of images, equivalent to SELECT COUNT(*) FROM image
+  ss_images int(10) default '0',
+
   UNIQUE KEY ss_row_id (ss_row_id)
 
 ) ENGINE=InnoDB;
index 9053646..b14b7b0 100644 (file)
@@ -507,6 +507,9 @@ CREATE TABLE /*$wgDBprefix*/site_stats (
   -- Deprecated, no longer updated as of 1.5
   ss_admins int(10) default '-1',
 
+  -- Number of images, equivalent to SELECT COUNT(*) FROM image
+  ss_images int(10) default '0',
+
   UNIQUE KEY ss_row_id (ss_row_id)
 
 ) ENGINE=InnoDB;
index 622b4df..6f33841 100644 (file)
@@ -54,6 +54,7 @@ $wgNewFields = array(
        array( 'site_stats',    'ss_total_pages',   'patch-ss_total_articles.sql' ),
        array( 'interwiki',     'iw_trans',         'patch-interwiki-trans.sql' ),
        array( 'ipblocks',      'ipb_range_start',  'patch-ipb_range_start.sql' ),
+       array( 'site_stats',    'ss_images',        'patch-ss_images.sql' ),
 );
 
 function rename_table( $from, $to, $patch ) {