From: Tim Starling Date: Tue, 28 Mar 2006 05:09:33 +0000 (+0000) Subject: Added ss_images to site_stats, to replace the slow count(*) query in Parser.php. X-Git-Tag: 1.6.0~95 X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/exercices/bilan.php?a=commitdiff_plain;h=98af136ad5608781df61a6c911056045b958df20;p=lhc%2Fweb%2Fwiklou.git Added ss_images to site_stats, to replace the slow count(*) query in Parser.php. --- diff --git a/includes/Image.php b/includes/Image.php index 96f8c5c568..9d23e95c9c 100644 --- a/includes/Image.php +++ b/includes/Image.php @@ -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 ); diff --git a/includes/ImagePage.php b/includes/ImagePage.php index 0e55156405..98feeb417d 100644 --- a/includes/ImagePage.php +++ b/includes/ImagePage.php @@ -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; } diff --git a/includes/Parser.php b/includes/Parser.php index a846fc80f5..ac06185a6e 100644 --- a/includes/Parser.php +++ b/includes/Parser.php @@ -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; } /** diff --git a/includes/SpecialStatistics.php b/includes/SpecialStatistics.php index f5583fe35b..6ff3338d4f 100644 --- a/includes/SpecialStatistics.php +++ b/includes/SpecialStatistics.php @@ -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"; diff --git a/languages/Messages.php b/languages/Messages.php index 55233b2765..3baa82413b 100644 --- a/languages/Messages.php +++ b/languages/Messages.php @@ -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 index 0000000000..2a9519bc5d --- /dev/null +++ b/maintenance/archives/patch-ss_images.sql @@ -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; diff --git a/maintenance/mysql5/tables.sql b/maintenance/mysql5/tables.sql index 2f0999ce7c..c2b9bc9f0c 100644 --- a/maintenance/mysql5/tables.sql +++ b/maintenance/mysql5/tables.sql @@ -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; diff --git a/maintenance/tables.sql b/maintenance/tables.sql index 9053646d5a..b14b7b0347 100644 --- a/maintenance/tables.sql +++ b/maintenance/tables.sql @@ -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; diff --git a/maintenance/updaters.inc b/maintenance/updaters.inc index 622b4df41c..6f33841d78 100644 --- a/maintenance/updaters.inc +++ b/maintenance/updaters.inc @@ -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 ) {