Version 5.0.0 release
This commit is contained in:
1 parent
90e8c7e903
commit
a3a4a9ccbd
651 files changed
+7275
-9481
No files matched your search
@@ -79,6 +79,7 @@ use function array_keys;
|
||||
use function array_merge;
|
||||
use function array_shift;
|
||||
use function array_slice;
|
||||
use function array_unique;
|
||||
use function count;
|
||||
use function defined;
|
||||
use function explode;
|
||||
@@ -89,6 +90,8 @@ use function is_array;
|
||||
use function json_decode;
|
||||
use function json_encode;
|
||||
use function krsort;
|
||||
use function strpos;
|
||||
use function substr;
|
||||
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
@@ -468,9 +471,15 @@ class Forum extends Model implements Permissions
|
||||
*/
|
||||
public function get_last_post() : ?int
|
||||
{
|
||||
$timestamps = array_keys( $this->_last_post_data );
|
||||
sort( $timestamps );
|
||||
return count( $timestamps ) ? array_pop( $timestamps ) : null;
|
||||
$lastPostTime = 0;
|
||||
foreach( $this->_last_post_data as $k => $v )
|
||||
{
|
||||
if( $v['last_post'] > $lastPostTime )
|
||||
{
|
||||
$lastPostTime = $v['last_post'];
|
||||
}
|
||||
}
|
||||
return $lastPostTime;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -560,7 +569,7 @@ class Forum extends Model implements Permissions
|
||||
}
|
||||
|
||||
$lastPostData = [
|
||||
$updatedItem->last_post => [
|
||||
$updatedItem->last_post . $updatedItem->tid => [
|
||||
'last_post' => $updatedItem->last_post,
|
||||
'last_poster_id' => $updatedItem->last_poster_id,
|
||||
'last_poster_name' => $updatedItem->last_poster_name,
|
||||
@@ -598,6 +607,12 @@ class Forum extends Model implements Permissions
|
||||
{
|
||||
$topic = Topic::constructFromData( $row );
|
||||
$lastComment = $topic->comments( 1, 0, 'date', 'desc', null, false );
|
||||
|
||||
if ( ! $lastComment )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$lastPost = [];
|
||||
if ( $topic->last_poster_id and ! $topic->last_poster_name )
|
||||
{
|
||||
@@ -628,7 +643,7 @@ class Forum extends Model implements Permissions
|
||||
$lastPost['last_post_snippet'] = $lastComment?->truncated( true, 350 );
|
||||
$lastPost['posts'] = $topic->posts - 1;
|
||||
|
||||
$lastPostData[ $topic->last_post ] = $lastPost;
|
||||
$lastPostData[ $topic->last_post . $topic->tid ] = $lastPost;
|
||||
}
|
||||
}
|
||||
catch ( UnderflowException $e ){}
|
||||
@@ -670,6 +685,13 @@ class Forum extends Model implements Permissions
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prevent looking up the same members constantly when building the last post members
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private static array $lastPostLoadedMembers = [];
|
||||
|
||||
/**
|
||||
* Get last post data
|
||||
*
|
||||
@@ -677,7 +699,7 @@ class Forum extends Model implements Permissions
|
||||
* @param bool $isChild
|
||||
* @return array|null
|
||||
*/
|
||||
public function lastPost( int $count=1, $isChild=false ): ?array
|
||||
public function lastPost( int $count=1, bool $isChild=false ): ?array
|
||||
{
|
||||
if ( $count > 5 )
|
||||
{
|
||||
@@ -778,7 +800,7 @@ class Forum extends Model implements Permissions
|
||||
$results = [];
|
||||
|
||||
/* Do we have any data, or do we need to update? The default or cleared state is NULL, forums without topics should have [] */
|
||||
if ( $this->sub_can_post and $this->posts and ! $this->club_id and ! $this->_data['last_post_data'] )
|
||||
if ( $this->sub_can_post and $this->posts and ! $this->_data['last_post_data'] )
|
||||
{
|
||||
$this->setLastComment();
|
||||
|
||||
@@ -811,7 +833,7 @@ class Forum extends Model implements Permissions
|
||||
'_author' => $author,
|
||||
'topic_url' => Url::internal( "app=forums&module=forums&controller=topic&id={$lastPost['last_id']}", 'front', 'forums_topic', array( $lastPost['seo_last_title'] ) ),
|
||||
'topic_title' => $lastPost['last_title'],
|
||||
'date' => $lastPostTime,
|
||||
'date' => ( $lastPost['last_post'] ?? (int) ( substr( $lastPostTime, 0, strpos( $lastPostTime, '.' ) ) ) ),
|
||||
'last_poster_anon' => $lastPost['last_poster_anon'],
|
||||
'last_post_snippet' => $lastPost['last_post_snippet'] ?? null,
|
||||
'posts' => $lastPost['posts'] ?? 0
|
||||
@@ -863,15 +885,31 @@ class Forum extends Model implements Permissions
|
||||
}
|
||||
}
|
||||
|
||||
$idsToLoad = array_unique( array_values( $membersToLoad ) );
|
||||
|
||||
/* Load the members not in static::$lastPostLoadedMembers */
|
||||
$idsToLoad = array_diff( $idsToLoad, array_keys( static::$lastPostLoadedMembers ) );
|
||||
|
||||
if ( count( $idsToLoad ) )
|
||||
{
|
||||
foreach( Db::i()->select( '*', 'core_members', [ Db::i()->in( 'member_id', $idsToLoad ) ] ) as $lastPostMember )
|
||||
{
|
||||
static::$lastPostLoadedMembers[ $lastPostMember['member_id'] ] = Member::constructFromData( $lastPostMember );
|
||||
}
|
||||
}
|
||||
|
||||
if ( count( $membersToLoad ) )
|
||||
{
|
||||
$membersLoaded = iterator_to_array( Db::i()->select( '*', 'core_members', [ Db::i()->in( 'member_id', $membersToLoad ) ] )->setKeyField( 'member_id' ) );
|
||||
|
||||
foreach ( $membersToLoad as $timestamp => $memberId )
|
||||
{
|
||||
if ( isset( $membersLoaded[$memberId] ) )
|
||||
if ( isset( static::$lastPostLoadedMembers[ $memberId ] ) )
|
||||
{
|
||||
$results[$timestamp]['author'] = Member::constructFromData( $membersLoaded[$memberId] );
|
||||
$results[$timestamp]['author'] = static::$lastPostLoadedMembers[ $memberId ];
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Technically we shouldn't ever get here, but let's not throw an exception */
|
||||
$results[$timestamp]['author'] = Member::load( $memberId );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user