Skip to content

Commit eef6d94

Browse files
fkgruberFred Grubercderv
authored
This commit fixes error when updating multiple confluence attachments (#13341)
* This commit fixes error when updating multiple confluence attachments Essentially, it uploads attachments one at a time instead of in parallel. Currently using a 0.8 second delay. * Fix indentation: convert tabs to spaces in attachment upload loop * Use existing sleep() helper instead of inline setTimeout * Extract attachment upload delay to named constant * Skip delay after last attachment upload * Preserve AttachmentSummary types instead of erasing to unknown * Remove redundant sleep timing trace * Add changelog entry for Confluence attachment upload fix (#12558) --------- Co-authored-by: Fred Gruber <[email protected]> Co-authored-by: Christophe Dervieux <[email protected]>
1 parent c875f08 commit eef6d94

3 files changed

Lines changed: 20 additions & 5 deletions

File tree

news/changelog-1.9.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ All changes included in 1.9:
135135

136136
### Confluence
137137

138+
- ([#12558](https://github.com/quarto-dev/quarto-cli/issues/12558)): Fix 500 error when updating multiple Confluence attachments. Attachments are now uploaded sequentially instead of concurrently. (author: @fkgruber)
138139
- ([#13414](https://github.com/quarto-dev/quarto-cli/issues/13414)): Be more forgiving when Confluence server returns malformed JSON response. (author: @m1no)
139140

140141
### `gh-pages`

src/publish/confluence/confluence.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ import {
8787
} from "./confluence-verify.ts";
8888
import {
8989
DELETE_DISABLED,
90+
ATTACHMENT_UPLOAD_DELAY_MS,
9091
DELETE_SLEEP_MILLIS,
9192
DESCENDANT_PAGE_SIZE,
9293
EXIT_ON_ERROR,
@@ -435,15 +436,25 @@ async function publish(
435436
LogPrefix.ATTACHMENT,
436437
);
437438

438-
const uploadAttachmentsResult = await Promise.all(
439-
uploadAttachments(
439+
const uploadAttachmentsResult: (AttachmentSummary | null)[] = [];
440+
441+
for (let i = 0; i < attachmentsToUpload.length; i++) {
442+
// Start exactly ONE upload by calling the helper with a single attachment
443+
const tasks = uploadAttachments(
440444
publishFiles.baseDir,
441-
attachmentsToUpload,
445+
[attachmentsToUpload[i]], // <-- one at a time
442446
toUpdate.id,
443447
fileName,
444448
existingAttachments,
445-
),
446-
);
449+
);
450+
451+
const res = await tasks[0];
452+
uploadAttachmentsResult.push(res);
453+
454+
if (i < attachmentsToUpload.length - 1) {
455+
await sleep(ATTACHMENT_UPLOAD_DELAY_MS);
456+
}
457+
}
447458
trace(
448459
"uploadAttachmentsResult",
449460
uploadAttachmentsResult,

src/publish/confluence/constants.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ export const V2EDITOR_METADATA = {
1818

1919
export const DELETE_SLEEP_MILLIS = 1000; //TODO replace with polling
2020

21+
// Empirically determined delay to avoid Confluence 500 errors on concurrent attachment updates
22+
export const ATTACHMENT_UPLOAD_DELAY_MS = 800;
23+
2124
export const CAN_SET_PERMISSIONS_DISABLED = "CONFLUENCE_LOCAL_STORAGE_CAN_SET_PERMISSIONS_DISABLED";
2225

2326
export const CAN_SET_PERMISSIONS_ENABLED_CACHED = "CONFLUENCE_LOCAL_STORAGE_CAN_SET_PERMISSIONS_ENABLED_CACHED"

0 commit comments

Comments
 (0)