Skip to content

Commit a600bf2

Browse files
fix(logs): batch conversation-query digests with Promise.all
React Doctor flagged the sequential await-in-loop in hashLogConversationQuery; candidates are independent, so map them through crypto.subtle.digest concurrently and keep result order. Co-Authored-By: Devin AI <devin-ai-integration[bot]@users.noreply.github.com>
1 parent 0df8335 commit a600bf2

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

‎gui/src/log-conversation-id.ts‎

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,15 @@ function logConversationQueryCandidates(query: string): string[] {
5353

5454
/** SHA-256 hex prefixes used as persisted conversation ids, one per query candidate. */
5555
export async function hashLogConversationQuery(raw: string): Promise<string[]> {
56-
const hashes: string[] = [];
57-
for (const candidate of logConversationQueryCandidates(raw)) {
58-
if (!candidate || hasControlChars(candidate) || candidate.length > 4096) continue;
59-
const digest = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(candidate));
60-
hashes.push(toHex(digest).slice(0, LOG_CONVERSATION_ID_LEN));
61-
}
62-
return hashes;
56+
const candidates = logConversationQueryCandidates(raw).filter(
57+
candidate => candidate !== "" && !hasControlChars(candidate) && candidate.length <= 4096,
58+
);
59+
const digests = await Promise.all(
60+
candidates.map(candidate =>
61+
crypto.subtle.digest("SHA-256", new TextEncoder().encode(candidate)),
62+
),
63+
);
64+
return digests.map(digest => toHex(digest).slice(0, LOG_CONVERSATION_ID_LEN));
6365
}
6466

6567
export function matchesLogConversationId(

0 commit comments

Comments
 (0)