/* 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;
$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 );
$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;