perf(messages): execute pesquisas de LID em paralelo

perf(messages): execute pesquisas de LID em paralelo
This commit is contained in:
Renato Alcara
2026-02-02 22:35:11 -03:00
committed by GitHub
3 changed files with 70 additions and 33 deletions
+34 -10
View File
@@ -15,6 +15,9 @@ on:
permissions: permissions:
contents: write contents: write
pull-requests: write pull-requests: write
# Note: Auto-merge may require additional permissions depending on repository settings.
# If auto-merge fails, consider using a Personal Access Token (PAT) or GitHub App token
# with 'pull-requests: write' and 'contents: write' scopes.
jobs: jobs:
update-version: update-version:
@@ -145,23 +148,44 @@ jobs:
> **Note:** This PR was created with force mode enabled." > **Note:** This PR was created with force mode enabled."
fi fi
# Create PR # Create PR with JSON output for reliable success detection
PR_URL=$(gh pr create \ PR_RESULT=$(gh pr create \
--title "chore: update WhatsApp Web version" \ --title "chore: update WhatsApp Web version" \
--body "$PR_BODY" \ --body "$PR_BODY" \
--base master \ --base master \
--head "$BRANCH_NAME" 2>&1) || true --head "$BRANCH_NAME" \
--json url,number 2>&1) || PR_CREATE_FAILED=true
if [[ "$PR_URL" == *"github.com"* ]]; then # Check if PR was created successfully by parsing JSON
echo "PR created: $PR_URL" if [ -z "$PR_CREATE_FAILED" ] && echo "$PR_RESULT" | jq -e '.url' > /dev/null 2>&1; then
PR_URL=$(echo "$PR_RESULT" | jq -r '.url')
PR_NUMBER=$(echo "$PR_RESULT" | jq -r '.number')
echo "PR created successfully: $PR_URL (PR #$PR_NUMBER)"
# Auto-merge the PR (squash merge) # Auto-merge the PR (squash merge)
echo "Attempting to auto-merge..." # Note: This requires branch protection rules to be satisfied
gh pr merge "$BRANCH_NAME" --squash --auto --delete-branch || \ # If checks haven't completed yet, auto-merge will queue the merge
gh pr merge "$BRANCH_NAME" --squash --delete-branch || \ echo "Attempting to enable auto-merge..."
echo "Auto-merge not available - PR created for manual review" if gh pr merge "$BRANCH_NAME" --squash --auto --delete-branch; then
echo "✅ Auto-merge enabled - PR will merge automatically when checks pass"
else
echo "⚠️ Auto-merge not available - PR #$PR_NUMBER created for manual review"
echo "This may happen if:"
echo " - Required status checks haven't completed yet"
echo " - Branch protection rules require manual approval"
echo " - Insufficient permissions (see workflow permissions comment)"
fi
else else
echo "PR already exists or could not be created: $PR_URL" # PR creation failed - could be duplicate or other error
echo "⚠️ Could not create PR. Checking if PR already exists..."
EXISTING_PR=$(gh pr list --head "$BRANCH_NAME" --json number,url --jq '.[0]')
if [ -n "$EXISTING_PR" ]; then
EXISTING_URL=$(echo "$EXISTING_PR" | jq -r '.url')
EXISTING_NUMBER=$(echo "$EXISTING_PR" | jq -r '.number')
echo "PR already exists: $EXISTING_URL (PR #$EXISTING_NUMBER)"
else
echo "❌ PR creation failed: $PR_RESULT"
fi
fi fi
- name: Summary - name: Summary
+30 -21
View File
@@ -1216,33 +1216,42 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
} = decryptMessageNode(node, authState.creds.me!.id, authState.creds.me!.lid || '', signalRepository, logger) } = decryptMessageNode(node, authState.creds.me!.id, authState.creds.me!.lid || '', signalRepository, logger)
const alt = msg.key.participantAlt || msg.key.remoteJidAlt const alt = msg.key.participantAlt || msg.key.remoteJidAlt
// Store LID/PN mappings asynchronously (fire-and-forget) to avoid blocking message delivery // Handle LID/PN mappings with hybrid approach:
// This improves inbound message latency by moving non-critical operations to background // - Store mapping operation runs in background (non-critical for decrypt)
// - Session migration MUST complete before decrypt() to avoid "No session record" errors
// This addresses Codex/Copilot review concerns about race conditions with decrypt()
if (!!alt) { if (!!alt) {
const altServer = jidDecode(alt)?.server const altServer = jidDecode(alt)?.server
const primaryJid = msg.key.participant || msg.key.remoteJid! const primaryJid = msg.key.participant || msg.key.remoteJid!
// Execute mapping operations in background without blocking message delivery if (altServer === 'lid') {
const processMappingAsync = async () => { // Check if mapping already exists to avoid unnecessary storage operations
try { const existingMapping = await signalRepository.lidMapping.getPNForLID(alt)
if (altServer === 'lid') { if (!existingMapping) {
if (!(await signalRepository.lidMapping.getPNForLID(alt))) { // Store mapping in background (non-critical, doesn't block decrypt)
await signalRepository.lidMapping.storeLIDPNMappings([{ lid: alt, pn: primaryJid }]) signalRepository.lidMapping.storeLIDPNMappings([{ lid: alt, pn: primaryJid }])
await signalRepository.migrateSession(primaryJid, alt) .catch(error => logger.warn({ error, alt, primaryJid }, 'Background LID mapping storage failed'))
}
} else {
await signalRepository.lidMapping.storeLIDPNMappings([{ lid: primaryJid, pn: alt }])
await signalRepository.migrateSession(alt, primaryJid)
}
} catch (error) {
logger.warn({ error, alt, primaryJid }, 'Background LID mapping operation failed')
} }
}
// Fire and forget - don't await // CRITICAL: ALWAYS migrate session, even if mapping exists
processMappingAsync().catch(error => { // Other code paths (e.g., USync device lookup in messages-send.ts:310-319)
logger.error({ error, alt, primaryJid }, 'Fatal error in background LID mapping') // may create mappings via storeLIDPNMappings() without calling migrateSession()
}) // This leaves sessions under PN format while decrypt() expects LID format
// Skipping migration based on mapping existence causes "No session record" errors
await signalRepository.migrateSession(primaryJid, alt)
} else {
// Check if reverse mapping exists
const existingMapping = await signalRepository.lidMapping.getLIDForPN(alt)
if (!existingMapping) {
// Store mapping in background (non-critical)
signalRepository.lidMapping.storeLIDPNMappings([{ lid: primaryJid, pn: alt }])
.catch(error => logger.warn({ error, alt, primaryJid }, 'Background LID mapping storage failed'))
}
// CRITICAL: ALWAYS migrate session, even if mapping exists
// Same reasoning as above - mapping existence doesn't guarantee session migration
await signalRepository.migrateSession(alt, primaryJid)
}
} }
if (msg.key?.remoteJid && msg.key?.id && messageRetryManager) { if (msg.key?.remoteJid && msg.key?.id && messageRetryManager) {
+6 -2
View File
@@ -131,12 +131,16 @@ export const normalizeMessageJids = async (
return jid return jid
} }
const resolvedRemoteJid = await resolveLidToPn(message.key.remoteJid) // Execute both lookups in parallel instead of sequentially to reduce latency
const [resolvedRemoteJid, resolvedParticipant] = await Promise.all([
resolveLidToPn(message.key.remoteJid),
resolveLidToPn(message.key.participant)
])
if (resolvedRemoteJid) { if (resolvedRemoteJid) {
message.key.remoteJid = resolvedRemoteJid message.key.remoteJid = resolvedRemoteJid
} }
const resolvedParticipant = await resolveLidToPn(message.key.participant)
if (resolvedParticipant) { if (resolvedParticipant) {
message.key.participant = resolvedParticipant message.key.participant = resolvedParticipant
} }