Parallelize 'channel_sign' calls.
## Issue If the account has lots of channels, each channel name was sequentially signed, delaying the final action.
This commit is contained in:
parent
eba8de1cda
commit
8da7ddf6e6
1 changed files with 102 additions and 86 deletions
|
@ -489,6 +489,22 @@ export function doCommentUpdate(comment_id: string, comment: string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function channelSignName(channelClaimId: string, channelName: string) {
|
||||||
|
let signedObject;
|
||||||
|
|
||||||
|
try {
|
||||||
|
signedObject = await Lbry.channel_sign({
|
||||||
|
channel_id: channelClaimId,
|
||||||
|
hexdata: toHex(channelName),
|
||||||
|
});
|
||||||
|
|
||||||
|
signedObject['claim_id'] = channelClaimId;
|
||||||
|
signedObject['name'] = channelName;
|
||||||
|
} catch (e) {}
|
||||||
|
|
||||||
|
return signedObject;
|
||||||
|
}
|
||||||
|
|
||||||
// Hides a users comments from all creator's claims and prevent them from commenting in the future
|
// Hides a users comments from all creator's claims and prevent them from commenting in the future
|
||||||
export function doCommentModToggleBlock(channelUri: string, unblock: boolean = false) {
|
export function doCommentModToggleBlock(channelUri: string, unblock: boolean = false) {
|
||||||
return async (dispatch: Dispatch, getState: GetState) => {
|
return async (dispatch: Dispatch, getState: GetState) => {
|
||||||
|
@ -512,18 +528,6 @@ export function doCommentModToggleBlock(channelUri: string, unblock: boolean = f
|
||||||
const creatorNameForAction = claim ? claim.name : null;
|
const creatorNameForAction = claim ? claim.name : null;
|
||||||
|
|
||||||
let channelSignatures = [];
|
let channelSignatures = [];
|
||||||
if (myChannels) {
|
|
||||||
for (const channelClaim of myChannels) {
|
|
||||||
try {
|
|
||||||
const channelSignature = await Lbry.channel_sign({
|
|
||||||
channel_id: channelClaim.claim_id,
|
|
||||||
hexdata: toHex(channelClaim.name),
|
|
||||||
});
|
|
||||||
|
|
||||||
channelSignatures.push({ ...channelSignature, claim_id: channelClaim.claim_id, name: channelClaim.name });
|
|
||||||
} catch (e) {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const sharedModBlockParams = unblock
|
const sharedModBlockParams = unblock
|
||||||
? {
|
? {
|
||||||
|
@ -536,9 +540,15 @@ export function doCommentModToggleBlock(channelUri: string, unblock: boolean = f
|
||||||
};
|
};
|
||||||
|
|
||||||
const commentAction = unblock ? Comments.moderation_unblock : Comments.moderation_block;
|
const commentAction = unblock ? Comments.moderation_unblock : Comments.moderation_block;
|
||||||
|
|
||||||
|
return Promise.all(myChannels.map((channel) => channelSignName(channel.claim_id, channel.name)))
|
||||||
|
.then((response) => {
|
||||||
|
channelSignatures = response;
|
||||||
// $FlowFixMe
|
// $FlowFixMe
|
||||||
return Promise.allSettled(
|
return Promise.allSettled(
|
||||||
channelSignatures.map((signatureData) =>
|
channelSignatures
|
||||||
|
.filter((x) => x !== undefined && x !== null)
|
||||||
|
.map((signatureData) =>
|
||||||
commentAction({
|
commentAction({
|
||||||
mod_channel_id: signatureData.claim_id,
|
mod_channel_id: signatureData.claim_id,
|
||||||
mod_channel_name: signatureData.name,
|
mod_channel_name: signatureData.name,
|
||||||
|
@ -563,6 +573,12 @@ export function doCommentModToggleBlock(channelUri: string, unblock: boolean = f
|
||||||
type: unblock ? ACTIONS.COMMENT_MODERATION_UN_BLOCK_FAILED : ACTIONS.COMMENT_MODERATION_BLOCK_FAILED,
|
type: unblock ? ACTIONS.COMMENT_MODERATION_UN_BLOCK_FAILED : ACTIONS.COMMENT_MODERATION_BLOCK_FAILED,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
dispatch({
|
||||||
|
type: unblock ? ACTIONS.COMMENT_MODERATION_UN_BLOCK_FAILED : ACTIONS.COMMENT_MODERATION_BLOCK_FAILED,
|
||||||
|
});
|
||||||
|
});
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -588,21 +604,15 @@ export function doFetchModBlockedList() {
|
||||||
});
|
});
|
||||||
|
|
||||||
let channelSignatures = [];
|
let channelSignatures = [];
|
||||||
if (myChannels) {
|
|
||||||
for (const channelClaim of myChannels) {
|
|
||||||
try {
|
|
||||||
const channelSignature = await Lbry.channel_sign({
|
|
||||||
channel_id: channelClaim.claim_id,
|
|
||||||
hexdata: toHex(channelClaim.name),
|
|
||||||
});
|
|
||||||
|
|
||||||
channelSignatures.push({ ...channelSignature, claim_id: channelClaim.claim_id, name: channelClaim.name });
|
return Promise.all(myChannels.map((channel) => channelSignName(channel.claim_id, channel.name)))
|
||||||
} catch (e) {}
|
.then((response) => {
|
||||||
}
|
channelSignatures = response;
|
||||||
}
|
|
||||||
// $FlowFixMe
|
// $FlowFixMe
|
||||||
return Promise.allSettled(
|
return Promise.allSettled(
|
||||||
channelSignatures.map((signatureData) =>
|
channelSignatures
|
||||||
|
.filter((x) => x !== undefined && x !== null)
|
||||||
|
.map((signatureData) =>
|
||||||
Comments.moderation_block_list({
|
Comments.moderation_block_list({
|
||||||
mod_channel_id: signatureData.claim_id,
|
mod_channel_id: signatureData.claim_id,
|
||||||
mod_channel_name: signatureData.name,
|
mod_channel_name: signatureData.name,
|
||||||
|
@ -653,6 +663,12 @@ export function doFetchModBlockedList() {
|
||||||
type: ACTIONS.COMMENT_MODERATION_BLOCK_LIST_FAILED,
|
type: ACTIONS.COMMENT_MODERATION_BLOCK_LIST_FAILED,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
dispatch({
|
||||||
|
type: ACTIONS.COMMENT_MODERATION_BLOCK_LIST_FAILED,
|
||||||
|
});
|
||||||
|
});
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue