Version 4.7.0
This commit is contained in:
1 parent
517a5e1f70
commit
8ba7d43898
1933 files changed
+65613
-11332
No files matched your search
@@ -83,6 +83,7 @@ trait Statistics
|
||||
catch( \OutOfRangeException $e )
|
||||
{
|
||||
$where = $this->_getVisibleWhere();
|
||||
$where[] = [ $commentClass::$databasePrefix . $commentClass::$databaseColumnMap['author'] . '!=?', 0];
|
||||
|
||||
$members = iterator_to_array( \IPS\Db::i()->select( "count(*) as sum, {$authorColumn}", $commentClass::$databaseTable, $where, 'sum DESC', array( 0, $count ), array( $commentClass::$databasePrefix . $commentClass::$databaseColumnMap['author'] ) ) );
|
||||
|
||||
@@ -108,6 +109,11 @@ trait Statistics
|
||||
$return[] = array( 'member' => $member, 'count' => $counts[ $member->member_id ] );
|
||||
}
|
||||
|
||||
usort($return, function ( $member, $member2 )
|
||||
{
|
||||
return $member2['count'] <=> $member['count'];
|
||||
});
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
@@ -247,7 +253,7 @@ trait Statistics
|
||||
public function clearCachedStatistics()
|
||||
{
|
||||
$idField = static::$databaseColumnId;
|
||||
\IPS\Db::i()->delete( 'core_item_statistics_cache', array( 'cache_class=? and cache_item_id=?', \get_class( $this ), $this->$idField ) );
|
||||
\IPS\Db::i()->delete( 'core_item_statistics_cache', array( 'cache_class=? and cache_item_id=?', \get_class( $this ), $this->$idField ) );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -378,17 +384,19 @@ trait Statistics
|
||||
*/
|
||||
protected function _getCached( $key )
|
||||
{
|
||||
if ( static::$cachedActivity === NULL )
|
||||
$idField = static::$databaseColumnId;
|
||||
|
||||
$class = \get_class( $this );
|
||||
$arrayKey = $class.'.'.$this->$idField;
|
||||
if ( !isset( static::$cachedActivity[$arrayKey] ) )
|
||||
{
|
||||
$idField = static::$databaseColumnId;
|
||||
|
||||
try
|
||||
{
|
||||
$cache = \IPS\Db::i()->select( '*', 'core_item_statistics_cache', array( 'cache_class=? and cache_item_id=?', \get_class( $this ), $this->$idField ) )->first();
|
||||
$cache = \IPS\Db::i()->select( '*', 'core_item_statistics_cache', array( 'cache_class=? and cache_item_id=?', $class, $this->$idField ) )->first();
|
||||
|
||||
if ( $cache['cache_added'] > time() - 86400 )
|
||||
{
|
||||
static::$cachedActivity = json_decode( $cache['cache_contents'], TRUE );
|
||||
static::$cachedActivity[ $arrayKey ] = json_decode( $cache['cache_contents'], TRUE );
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -398,18 +406,18 @@ trait Statistics
|
||||
catch( \UnderflowException $e ) { }
|
||||
}
|
||||
|
||||
if ( static::$cachedActivity !== NULL and isset( static::$cachedActivity[ $key ] ) )
|
||||
if ( isset(static::$cachedActivity[ $arrayKey ] ) and isset( static::$cachedActivity[ $arrayKey ][ $key ] ) )
|
||||
{
|
||||
return static::$cachedActivity[ $key ];
|
||||
return static::$cachedActivity[ $arrayKey ][ $key ];
|
||||
}
|
||||
else
|
||||
{
|
||||
if( static::$cachedActivity === NULL )
|
||||
if( !isset( static::$cachedActivity[ $arrayKey ] ) )
|
||||
{
|
||||
static::$cachedActivity = array();
|
||||
static::$cachedActivity[ $arrayKey ] = array();
|
||||
}
|
||||
|
||||
static::$cachedActivity[ $key ] = array();
|
||||
static::$cachedActivity[ $arrayKey ][ $key ] = array();
|
||||
throw new \OutOfRangeException;
|
||||
}
|
||||
}
|
||||
@@ -435,10 +443,12 @@ trait Statistics
|
||||
catch( \Exception $e ) { }
|
||||
|
||||
$idField = static::$databaseColumnId;
|
||||
|
||||
static::$cachedActivity[ $key ] = $value;
|
||||
$class = \get_class( $this );
|
||||
$arrayKey = $class.'.'.$this->$idField;
|
||||
|
||||
$this->storeCache = $this->$idField;
|
||||
static::$cachedActivity[ $arrayKey ][ $key ] = $value;
|
||||
|
||||
$this->storeCache[ $arrayKey ][ $key ] = $this->$idField;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -450,12 +460,15 @@ trait Statistics
|
||||
{
|
||||
if( $this->storeCache )
|
||||
{
|
||||
\IPS\Db::i()->insert( 'core_item_statistics_cache', array(
|
||||
'cache_class' => \get_class( $this ),
|
||||
'cache_item_id' => $this->storeCache,
|
||||
'cache_contents' => json_encode( static::$cachedActivity ),
|
||||
'cache_added' => time()
|
||||
), TRUE );
|
||||
foreach( $this->storeCache as $key => $data )
|
||||
{
|
||||
\IPS\Db::i()->insert( 'core_item_statistics_cache', array(
|
||||
'cache_class' => \get_class( $this ),
|
||||
'cache_item_id' => str_replace( \get_class($this) . '.', '', $key),
|
||||
'cache_contents' => json_encode( static::$cachedActivity[$key] ),
|
||||
'cache_added' => time()
|
||||
), TRUE );
|
||||
}
|
||||
}
|
||||
|
||||
if( \is_callable( 'parent::__destruct' ) )
|
||||
|
||||
Reference in new issue
Block a user