Skip to content

Commit

Permalink
Merge pull request #7451 from opengovsg/release-v6.130.1
Browse files Browse the repository at this point in the history
fix(attachment): convoy separation (#7449)
  • Loading branch information
KenLSM authored Jun 28, 2024
2 parents 6779dd6 + f1acaf0 commit 9b98847
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 6 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,21 @@ All notable changes to this project will be documented in this file. Dates are d

Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).

#### [v6.130.1](https://github.com/opengovsg/FormSG/compare/v6.130.0...v6.130.1)

- fix(attachment): convoy separation [`#7449`](https://github.com/opengovsg/FormSG/pull/7449)
- build: release v6.130.0 [`#7441`](https://github.com/opengovsg/FormSG/pull/7441)

#### [v6.130.0](https://github.com/opengovsg/FormSG/compare/v6.129.0...v6.130.0)

> 26 June 2024

- feat: update to platform flag [`#7437`](https://github.com/opengovsg/FormSG/pull/7437)
- feat(mrf): multiple static emails [`#7433`](https://github.com/opengovsg/FormSG/pull/7433)
- build: merge release v6.129.0 to develop [`#7434`](https://github.com/opengovsg/FormSG/pull/7434)
- chore(deps-dev): bump axios-mock-adapter from 1.21.4 to 1.22.0 [`#7435`](https://github.com/opengovsg/FormSG/pull/7435)
- build: release v6.129.0 [`#7432`](https://github.com/opengovsg/FormSG/pull/7432)
- chore: bump version to v6.130.0 [`295ed77`](https://github.com/opengovsg/FormSG/commit/295ed7717a904ef19b32531e0f2e7dfcc919fa87)

#### [v6.129.0](https://github.com/opengovsg/FormSG/compare/v6.128.0...v6.129.0)

Expand Down
4 changes: 2 additions & 2 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "form-frontend",
"version": "6.130.0",
"version": "6.130.1",
"homepage": ".",
"private": true,
"dependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { useCallback, useEffect, useRef, useState } from 'react'
import { useMutation, UseMutationOptions } from 'react-query'
import { datadogLogs } from '@datadog/browser-logs'

import { waitForMs } from '~utils/waitForMs'

import { useAdminForm } from '~features/admin-form/common/queries'
import {
trackDownloadNetworkFailure,
Expand All @@ -27,6 +29,12 @@ import {

const NUM_OF_METADATA_ROWS = 5

// We will download attachments in convoys of 5
// This is to prevent the script from downloading too many attachments at once
// which could cause it to block downloads.
const ATTACHMENT_DOWNLOAD_CONVOY_SIZE = 5
const ATTACHMENT_DOWNLOAD_CONVOY_MINIMUM_SEPARATION_TIME = 1000

const killWorkers = (workers: CleanableDecryptionWorkerApi[]): void => {
return workers.forEach((worker) => worker.cleanup())
}
Expand Down Expand Up @@ -141,6 +149,7 @@ const useDecryptionWorkers = ({
const downloadStartTime = performance.now()

let progress = 0
let timeSinceLastXAttachmentDownload = 0

return new Promise<DownloadResult>((resolve, reject) => {
reader
Expand Down Expand Up @@ -181,7 +190,24 @@ const useDecryptionWorkers = ({
errorCount++
console.error('Error in getResponseInstance', e)
}

if (downloadAttachments && decryptResult.downloadBlob) {
// Ensure attachments downloads are spaced out to avoid browser blocking downloads
if (progress % ATTACHMENT_DOWNLOAD_CONVOY_SIZE === 0) {
const now = new Date().getTime()
const elapsedSinceXDownloads =
now - timeSinceLastXAttachmentDownload

const waitTime = Math.max(
0,
ATTACHMENT_DOWNLOAD_CONVOY_MINIMUM_SEPARATION_TIME -
elapsedSinceXDownloads,
)
if (waitTime > 0) {
await waitForMs(waitTime)
}
timeSinceLastXAttachmentDownload = now
}
await downloadResponseAttachment(
decryptResult.downloadBlob,
decryptResult.id,
Expand Down
5 changes: 5 additions & 0 deletions frontend/src/utils/waitForMs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const waitForMs = (ms: number): Promise<void> => {
return new Promise((resolve) => {
setTimeout(resolve, ms)
})
}
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "FormSG",
"description": "Form Manager for Government",
"version": "6.130.0",
"version": "6.130.1",
"homepage": "https://form.gov.sg",
"authors": [
"FormSG <[email protected]>"
Expand Down

0 comments on commit 9b98847

Please sign in to comment.