Split addSingleMessage
for better batching
This commit is contained in:
parent
f7c3a44056
commit
2aac3b5cb9
1 changed files with 15 additions and 2 deletions
|
@ -1389,6 +1389,11 @@ export class ConversationModel extends window.Backbone
|
||||||
message: MessageModel,
|
message: MessageModel,
|
||||||
{ isJustSent }: { isJustSent: boolean } = { isJustSent: false }
|
{ isJustSent }: { isJustSent: boolean } = { isJustSent: false }
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
|
await this.beforeAddSingleMessage();
|
||||||
|
this.doAddSingleMessage(message, { isJustSent });
|
||||||
|
}
|
||||||
|
|
||||||
|
private async beforeAddSingleMessage(): Promise<void> {
|
||||||
if (!this.newMessageQueue) {
|
if (!this.newMessageQueue) {
|
||||||
this.newMessageQueue = new window.PQueue({
|
this.newMessageQueue = new window.PQueue({
|
||||||
concurrency: 1,
|
concurrency: 1,
|
||||||
|
@ -1400,7 +1405,12 @@ export class ConversationModel extends window.Backbone
|
||||||
await this.newMessageQueue.add(async () => {
|
await this.newMessageQueue.add(async () => {
|
||||||
await this.inProgressFetch;
|
await this.inProgressFetch;
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private doAddSingleMessage(
|
||||||
|
message: MessageModel,
|
||||||
|
{ isJustSent }: { isJustSent: boolean }
|
||||||
|
): void {
|
||||||
const { messagesAdded } = window.reduxActions.conversations;
|
const { messagesAdded } = window.reduxActions.conversations;
|
||||||
const { conversations } = window.reduxStore.getState();
|
const { conversations } = window.reduxStore.getState();
|
||||||
const { messagesByConversation } = conversations;
|
const { messagesByConversation } = conversations;
|
||||||
|
@ -1414,7 +1424,7 @@ export class ConversationModel extends window.Backbone
|
||||||
newestId && messageIds && messageIds[messageIds.length - 1] === newestId;
|
newestId && messageIds && messageIds[messageIds.length - 1] === newestId;
|
||||||
|
|
||||||
if (isJustSent && existingConversation && !isLatestInMemory) {
|
if (isJustSent && existingConversation && !isLatestInMemory) {
|
||||||
await this.loadNewestMessages(undefined, undefined);
|
this.loadNewestMessages(undefined, undefined);
|
||||||
} else {
|
} else {
|
||||||
messagesAdded({
|
messagesAdded({
|
||||||
conversationId,
|
conversationId,
|
||||||
|
@ -4042,6 +4052,9 @@ export class ConversationModel extends window.Backbone
|
||||||
|
|
||||||
const renderStart = Date.now();
|
const renderStart = Date.now();
|
||||||
|
|
||||||
|
// Perform asynchronous tasks before entering the batching mode
|
||||||
|
await this.beforeAddSingleMessage();
|
||||||
|
|
||||||
this.isInReduxBatch = true;
|
this.isInReduxBatch = true;
|
||||||
batchDispatch(() => {
|
batchDispatch(() => {
|
||||||
try {
|
try {
|
||||||
|
@ -4051,7 +4064,7 @@ export class ConversationModel extends window.Backbone
|
||||||
const enableProfileSharing = Boolean(
|
const enableProfileSharing = Boolean(
|
||||||
mandatoryProfileSharingEnabled && !this.get('profileSharing')
|
mandatoryProfileSharingEnabled && !this.get('profileSharing')
|
||||||
);
|
);
|
||||||
this.addSingleMessage(model, { isJustSent: true });
|
this.doAddSingleMessage(model, { isJustSent: true });
|
||||||
|
|
||||||
const draftProperties = dontClearDraft
|
const draftProperties = dontClearDraft
|
||||||
? {}
|
? {}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue