Added pref which can be used to enable faster page hit counter feature. Default...
authorMr. E23 <e23@users.mediawiki.org>
Sat, 17 Jan 2004 19:59:42 +0000 (19:59 +0000)
committerMr. E23 <e23@users.mediawiki.org>
Sat, 17 Jan 2004 19:59:42 +0000 (19:59 +0000)
includes/Article.php
includes/DefaultSettings.php

index 5ef6bc9..3a7cdf4 100644 (file)
@@ -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 );
 
index f226f2e..9f2832f 100644 (file)
@@ -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;