From: Mr. E23 Date: Sat, 17 Jan 2004 19:59:42 +0000 (+0000) Subject: Added pref which can be used to enable faster page hit counter feature. Default... X-Git-Tag: 1.3.0beta1~1149 X-Git-Url: http://git.cyclocoop.org/%28?a=commitdiff_plain;h=7096a0b2279de597f890e6760a1aa7337a43d8cf;p=lhc%2Fweb%2Fwiklou.git Added pref which can be used to enable faster page hit counter feature. Default is to do it the old way. --- diff --git a/includes/Article.php b/includes/Article.php index 5ef6bc9819..3a7cdf47b4 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -1184,13 +1184,21 @@ class Article { /* static */ function incViewCount( $id ) { $id = intval( $id ); + global $wgHitcounterUpdateFreq; + + if( $wgHitcounterUpdateFreq <= 1 ){ // + wfQuery("UPDATE cur SET cur_counter = cur_counter + 1 " . + "WHERE cur_id = $id", DB_WRITE); + return; + } # Not important enough to warrant an error page in case of failure $oldignore = wfIgnoreSQLErrors( true ); wfQuery("INSERT INTO hitcounter (hc_id) VALUES ({$id})", DB_WRITE); - if( (rand() % 23 != 0) or (wfLastErrno() != 0) ){ + $checkfreq = intval( $wgHitcounterUpdateFreq/25 + 1 ); + if( (rand() % $checkfreq != 0) or (wfLastErrno() != 0) ){ # Most of the time (or on SQL errors), skip row count check wfIgnoreSQLErrors( $oldignore ); return; @@ -1199,7 +1207,7 @@ class Article { $res = wfQuery("SELECT COUNT(*) as n FROM hitcounter", DB_WRITE); $row = wfFetchObject( $res ); $rown = intval( $row->n ); - if( $rown > 1000 ){ // update counters after ~1000 hits + if( $rown >= $wgHitcounterUpdateFreq ){ wfProfileIn( "Article::incViewCount-collect" ); $old_user_abort = ignore_user_abort( true ); diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index f226f2ed40..9f2832fb28 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -92,6 +92,14 @@ $wgCompressedPersistentLC = true; # use gzcompressed blobs $wgEnableParserCache = false; # requires that php was compiled --with-zlib +# wgHitcounterUpdateFreq sets how often page counters should be +# updated, higher values are easier on the database. A value of 1 +# causes the counters to be updated on every hit, any higher value n +# cause them to update *on average* every n hits. Should be set to +# either 1 or something largish, eg 1000, for maximum efficiency. + +$wgHitcounterUpdateFreq = 1; + # User rights $wgWhitelistEdit = false; $wgWhitelistRead = false;