Added pref which can be used to enable faster page hit counter feature. Default is to do it the old way.
This commit is contained in:
parent
c4ab1c9bf3
commit
7096a0b227
2 changed files with 18 additions and 2 deletions
|
|
@ -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 );
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in a new issue