Multiple insertion management #755
-
Hello @demchenkoalex I encountered an issue that might be worth discussing. Basically my chat controller manages a List of Message. it basically does that but has to loop on all the messages already in the list so if it gets big , and since I know where to insert, I feel it will be way more performant. My problem is since we listen to a Stream of Operations it's async so when you do This actually breaks my PR #754 because I was thinking we should only rely on the local state (made a test here but this also has drawbacks: since Operations are executed in parralel we might end up with ops overwritting _oldList. It think it's only fixable with a queue of operations, but once again i'm not a Dart pro. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
Should we just introduce |
Beta Was this translation helpful? Give feedback.
-
@demchenkoalex That would be a nice addition ! Usually the client knows where to insert (at start or beginning of the list) so this would ensure good performance for very big chats, especially now that v2 easily handles Sembast or any other local storage (so all previous messages will be there) But i'm not sure this solves the core issue: The stream of Operations being async it makes it risky to rely on chatController's messages. This fix in #754 will never be safe because at some point we might try to insertItem in the scrollview at an idem bigger than it's 1. Quick and dirty
2.Expect the operation to be quick enough Best? : A queue of ops Something like List<ChatOperation> _operationsQueue;
bool _isProcessingOpsQueue = false;
void _processQueue() {
// Safety to no process twice, should not really happen
if (_isProcessingOpsQueue) return;
_isProcessingOpsQueue = true;
while (_operationsQueue.isNotEmpty) {
final ops = List.of(_operationsQueue);
_operationsQueue.clear();
// process ops synchronously
}
_isProcessingOpsQueue = false;
} and on new stream emit we insert in the queue + call processQueue |
Beta Was this translation helpful? Give feedback.
should be solved by #756