Version 5.0.0 release

This commit is contained in:
Neo committed 2025-12-19 18:37:58 -08:00
1 parent 90e8c7e903
commit a3a4a9ccbd
651 files changed
+7275 -9481

No files matched your search

+50 -12
View File
@@ -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 );
}
}
}
+23 -11
View File
@@ -73,6 +73,7 @@ use OutOfRangeException;
use RuntimeException;
use SplObserver;
use SplSubject;
use function array_reverse;
use function array_slice;
use function count;
use function defined;
@@ -1654,22 +1655,33 @@ class Topic extends Item implements Embeddable,
$minMax = ( $orderDirection === 'asc' ) ? 'MIN' : 'MAX';
/* Do some mojo to get the lowest comment and highest comment for archived topics */
$row = ArchivedPost::db()->select( "{$minMax}( CONCAT( archive_content_date, '.', archive_id) ) as pid", 'forums_archive_posts', array( [ 'archive_topic_id=?', $this->tid, ArchivedPost::db()->in( 'archive_queued', [0,2] ) ] ) )->first();
$pid = (int) explode( '.', $row )[1];
if( is_array( $extraWhereClause ) or is_null( $extraWhereClause ) )
if ( ! $row )
{
$extraWhereClause[] = [ 'archive_id=?', $pid ];
$comments[ $_hash ] = [];
}
else if ( is_string( $extraWhereClause ) )
else
{
$extraWhereClause = [
[ $extraWhereClause ],
[ 'archive_id=?', $pid ]
];
}
$pid = (int)explode( '.', $row )[1];
$data = $this->_comments( $class, 1, 0, ( isset( $class::$databaseColumnMap[$order] ) ? ( $class::$databasePrefix . $class::$databaseColumnMap[$order] ) : $order ) . ' ' . $orderDirection, $member, $includeHiddenComments, $cutoff, $canViewWarn, $extraWhereClause, $includeDeleted );
$comments[ $_hash ] = is_array( $data ) ? array_reverse( $data, true ) : $data;
if ( is_array( $extraWhereClause ) or is_null( $extraWhereClause ) )
{
$extraWhereClause[] = ['archive_id=?', $pid];
}
else
{
if ( is_string( $extraWhereClause ) )
{
$extraWhereClause = [
[$extraWhereClause],
['archive_id=?', $pid]
];
}
}
$data = $this->_comments( $class, 1, 0, ( isset( $class::$databaseColumnMap[$order] ) ? ( $class::$databasePrefix . $class::$databaseColumnMap[$order] ) : $order ) . ' ' . $orderDirection, $member, $includeHiddenComments, $cutoff, $canViewWarn, $extraWhereClause, $includeDeleted );
$comments[$_hash] = is_array( $data ) ? array_reverse( $data, true ) : $data;
}
$alreadyDone = true;
}