Skip to content

Commit

Permalink
[keyserver] Create toggle pin messages and updates in parallel
Browse files Browse the repository at this point in the history
Summary:
Some feedback [[
https://phab.comm.dev/D8683?id=29441#inline-56118 | here ]] was to try to
create the new messages and the updates in parallel by passing two
separate async IIFEs into a `Promise.all([...])`.

Depends on D8732

Test Plan:
Tested to make sure the new messages and the updates still
occur as before

Reviewers: atul, ginsu, ashoat

Reviewed By: ashoat

Subscribers: tomek

Differential Revision: https://phab.comm.dev/D8733
  • Loading branch information
RohanK6 committed Aug 7, 2023
1 parent 1f65502 commit 781c2d3
Showing 1 changed file with 31 additions and 21 deletions.
52 changes: 31 additions & 21 deletions keyserver/src/updaters/thread-updaters.js
Original file line number Diff line number Diff line change
Expand Up @@ -908,31 +908,41 @@ async function toggleMessagePinForThread(
};
}

const messageData = {
type: messageTypes.TOGGLE_PIN,
threadID,
targetMessageID: messageID,
action,
pinnedContent: getPinnedContentFromMessage(targetMessage),
creatorID: viewer.userID,
time: Date.now(),
const createMessagesAsync = async () => {
const messageData = {
type: messageTypes.TOGGLE_PIN,
threadID,
targetMessageID: messageID,
action,
pinnedContent: getPinnedContentFromMessage(targetMessage),
creatorID: viewer.userID,
time: Date.now(),
};
const newMessageInfos = await createMessages(viewer, [messageData]);
return newMessageInfos;
};
const newMessageInfos = await createMessages(viewer, [messageData]);

const { threadInfos: serverThreadInfos } = await fetchServerThreadInfos({
threadID,
});
const time = Date.now();
const updates = [];
for (const member of serverThreadInfos[threadID].members) {
updates.push({
userID: member.id,
time,
const createUpdatesAsync = async () => {
const { threadInfos: serverThreadInfos } = await fetchServerThreadInfos({
threadID,
type: updateTypes.UPDATE_THREAD,
});
}
await createUpdates(updates);
const time = Date.now();
const updates = [];
for (const member of serverThreadInfos[threadID].members) {
updates.push({
userID: member.id,
time,
threadID,
type: updateTypes.UPDATE_THREAD,
});
}
await createUpdates(updates);
};

const [newMessageInfos] = await Promise.all([
createMessagesAsync(),
createUpdatesAsync(),
]);

return {
newMessageInfos,
Expand Down

0 comments on commit 781c2d3

Please sign in to comment.