Version 4.7.0
This commit is contained in:
1 parent
517a5e1f70
commit
8ba7d43898
1933 files changed
+65613
-11332
No files matched your search
@@ -41,7 +41,6 @@ class _viewupdates extends \IPS\Task
|
||||
try
|
||||
{
|
||||
$database = \IPS\Db::i()->select( 'classname, id, count(*) AS count', 'core_view_updates', NULL, NULL, 20, array( 'classname', 'id' ), NULL, \IPS\Db::SELECT_FROM_WRITE_SERVER );
|
||||
$redis = array();
|
||||
|
||||
/* Database results first */
|
||||
foreach( $database as $row )
|
||||
@@ -69,44 +68,50 @@ class _viewupdates extends \IPS\Task
|
||||
{
|
||||
$redis = \IPS\Redis::i()->zRevRangeByScore( 'topic_views', '+inf', '-inf', array('withscores' => TRUE, 'limit' => array( 0, 20 ) ) );
|
||||
|
||||
foreach( $redis as $data => $count )
|
||||
if( \is_array( $redis ) )
|
||||
{
|
||||
$hasCount = TRUE;
|
||||
|
||||
list( $class, $id ) = explode( '__', $data );
|
||||
|
||||
try
|
||||
foreach ( $redis as $data => $count )
|
||||
{
|
||||
$this->update( $class, $id, \intval( $count ) );
|
||||
$hasCount = TRUE;
|
||||
|
||||
list( $class, $id ) = explode( '__', $data );
|
||||
|
||||
try
|
||||
{
|
||||
$this->update( $class, $id, \intval( $count ) );
|
||||
}
|
||||
catch ( \OutOfRangeException $e ) {}
|
||||
}
|
||||
|
||||
\IPS\Redis::i()->zRem( 'topic_views', ...array_keys( $redis ) );
|
||||
}
|
||||
}
|
||||
catch( \Exception $e ) { }
|
||||
|
||||
/* Now try advert impressions */
|
||||
try
|
||||
{
|
||||
$redis = \IPS\Redis::i()->zRevRangeByScore( 'advert_impressions', '+inf', '-inf', array('withscores' => TRUE, 'limit' => array( 0, 20 ) ) );
|
||||
|
||||
if( \is_array( $redis ) )
|
||||
{
|
||||
$updates = [];
|
||||
foreach ( $redis as $id => $count )
|
||||
{
|
||||
$hasCount = TRUE;
|
||||
$updates[ $count ][] = $id;
|
||||
|
||||
\IPS\Redis::i()->zRem( 'advert_impressions', $id );
|
||||
}
|
||||
|
||||
foreach ( $updates as $incrementBy => $ids )
|
||||
{
|
||||
\IPS\Db::i()->update( 'core_advertisements', "ad_impressions=ad_impressions+" . $incrementBy, [ \IPS\Db::i()->in( 'ad_id', $ids ) ] );
|
||||
}
|
||||
catch( \OutOfRangeException $e ) { }
|
||||
|
||||
\IPS\Redis::i()->zRem( 'topic_views', $data );
|
||||
}
|
||||
}
|
||||
catch( \Exception $e ) { }
|
||||
}
|
||||
|
||||
/* Now try advert impressions */
|
||||
try
|
||||
{
|
||||
$redis = \IPS\Redis::i()->zRevRangeByScore( 'advert_impressions', '+inf', '-inf', array('withscores' => TRUE, 'limit' => array( 0, 20 ) ) );
|
||||
$updates = [];
|
||||
|
||||
foreach( $redis as $id => $count )
|
||||
{
|
||||
$hasCount = TRUE;
|
||||
$updates[ $count ][] = $id;
|
||||
|
||||
\IPS\Redis::i()->zRem( 'advert_impressions', $id );
|
||||
}
|
||||
|
||||
foreach( $updates as $incrementBy => $ids )
|
||||
{
|
||||
\IPS\Db::i()->update( 'core_advertisements', "ad_impressions=ad_impressions+" . $incrementBy, [ \IPS\Db::i()->in( 'ad_id', $ids ) ] );
|
||||
}
|
||||
}
|
||||
catch( \Exception $e ) { }
|
||||
|
||||
/* Go for another go? */
|
||||
if ( $hasCount === TRUE )
|
||||
|
||||
Reference in new issue
Block a user