Remove renderMessages & revert msg limit to 5k
The separate list for render messages seems to have little effect for performance, so removing it. There has been some odd performance side effects with having a 10k message limit, so I've reverted that as well.
This commit is contained in:
parent
ec8cb421b0
commit
5e1c41dc02
3 changed files with 4 additions and 28 deletions
|
|
@ -42,9 +42,9 @@ class Chat extends StatelessWidget {
|
|||
padding: EdgeInsets.zero,
|
||||
addAutomaticKeepAlives: false,
|
||||
controller: chatStore.scrollController,
|
||||
itemCount: chatStore.renderMessages.length,
|
||||
itemCount: chatStore.messages.length,
|
||||
itemBuilder: (context, index) => ChatMessage(
|
||||
ircMessage: chatStore.renderMessages.reversed.toList()[index],
|
||||
ircMessage: chatStore.messages.reversed.toList()[index],
|
||||
chatStore: chatStore,
|
||||
),
|
||||
);
|
||||
|
|
|
|||
|
|
@ -20,10 +20,7 @@ class ChatStore = ChatStoreBase with _$ChatStore;
|
|||
|
||||
abstract class ChatStoreBase with Store {
|
||||
/// The total maximum amount of messages in chat.
|
||||
static const _messageLimit = 10000;
|
||||
|
||||
/// The maximum ammount of messages to render when autoscroll is enabled.
|
||||
static const _renderMessageLimit = 100;
|
||||
static const _messageLimit = 5000;
|
||||
|
||||
/// The amount of messages to free (remove) when the [_messageLimit] is reached.
|
||||
final _messagesToRemove = (_messageLimit * 0.2).toInt();
|
||||
|
|
@ -94,18 +91,6 @@ abstract class ChatStoreBase with Store {
|
|||
@readonly
|
||||
var _messages = ObservableList<IRCMessage>();
|
||||
|
||||
@computed
|
||||
List<IRCMessage> get renderMessages {
|
||||
// If autoscroll is disabled, render ALL messages in chat.
|
||||
// The second condition is to prevent an out of index error with sublist.
|
||||
if (!_autoScroll || _messages.length < _renderMessageLimit) return _messages;
|
||||
|
||||
// When autoscroll is enabled, only show the first [_renderMessageLimit] messages.
|
||||
// This will improve performance by only rendering a limited amount of messages
|
||||
// instead of the entire history at all times.
|
||||
return _messages.sublist(_messages.length - _renderMessageLimit);
|
||||
}
|
||||
|
||||
/// If the chat should automatically scroll/jump to the latest message.
|
||||
@readonly
|
||||
var _autoScroll = true;
|
||||
|
|
|
|||
|
|
@ -9,14 +9,6 @@ part of 'chat_store.dart';
|
|||
// ignore_for_file: non_constant_identifier_names, unnecessary_brace_in_string_interps, unnecessary_lambdas, prefer_expression_function_bodies, lines_longer_than_80_chars, avoid_as, avoid_annotating_with_dynamic, no_leading_underscores_for_local_identifiers
|
||||
|
||||
mixin _$ChatStore on ChatStoreBase, Store {
|
||||
Computed<List<IRCMessage>>? _$renderMessagesComputed;
|
||||
|
||||
@override
|
||||
List<IRCMessage> get renderMessages => (_$renderMessagesComputed ??=
|
||||
Computed<List<IRCMessage>>(() => super.renderMessages,
|
||||
name: 'ChatStoreBase.renderMessages'))
|
||||
.value;
|
||||
|
||||
late final _$_notificationAtom =
|
||||
Atom(name: 'ChatStoreBase._notification', context: context);
|
||||
|
||||
|
|
@ -252,8 +244,7 @@ mixin _$ChatStore on ChatStoreBase, Store {
|
|||
@override
|
||||
String toString() {
|
||||
return '''
|
||||
expandChat: ${expandChat},
|
||||
renderMessages: ${renderMessages}
|
||||
expandChat: ${expandChat}
|
||||
''';
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue