Skip to content

Commit 729c8f5

Browse files
authored
fix: capture failing version requests (#220)
1 parent 51a6732 commit 729c8f5

File tree

4 files changed

+456
-5
lines changed

4 files changed

+456
-5
lines changed

package-lock.json

Lines changed: 18 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
"*.cjs": "eslint"
5252
},
5353
"dependencies": {
54+
"@adobe/helix-shared-process-queue": "3.1.3",
5455
"@aws-sdk/client-s3": "3.726.1",
5556
"@aws-sdk/s3-request-presigner": "^3.468.0",
5657
"@cloudflare/workers-types": "4.20251126.0",

src/storage/version/list.js

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,36 @@
99
* OF ANY KIND, either express or implied. See the License for the specific language
1010
* governing permissions and limitations under the License.
1111
*/
12+
import processQueue from '@adobe/helix-shared-process-queue';
1213
import getObject from '../object/get.js';
1314
import listObjects from '../object/list.js';
1415

16+
const MAX_VERSIONS = 500;
17+
const CONCURRENCY = 50;
18+
1519
export async function listObjectVersions(env, { bucket, org, key }) {
1620
const current = await getObject(env, { bucket, org, key }, true);
1721
if (current.status === 404 || !current.metadata.id) {
1822
return 404;
1923
}
20-
const resp = await listObjects(env, { bucket, org, key: `.da-versions/${current.metadata.id}` }, 500);
21-
const promises = await Promise.all(JSON.parse(resp.body).map(async (entry) => {
24+
const resp = await listObjects(env, { bucket, org, key: `.da-versions/${current.metadata.id}` }, MAX_VERSIONS);
25+
if (resp.status !== 200) {
26+
return resp;
27+
}
28+
const list = JSON.parse(resp.body);
29+
30+
const versions = await processQueue(list, async (entry) => {
2231
const entryResp = await getObject(env, {
2332
bucket,
2433
org,
2534
key: `.da-versions/${current.metadata.id}/${entry.name}.${entry.ext}`,
2635
}, true);
36+
37+
if (entryResp.status !== 200 || !entryResp.metadata) {
38+
// Some requests might fail for unknown reasons (system busy, etc.)
39+
return undefined;
40+
}
41+
2742
const timestamp = parseInt(entryResp.metadata.timestamp || '0', 10);
2843
const users = JSON.parse(entryResp.metadata.users || '[{"email":"anonymous"}]');
2944
const { label, path } = entryResp.metadata;
@@ -38,11 +53,14 @@ export async function listObjectVersions(env, { bucket, org, key }) {
3853
};
3954
}
4055
return { users, timestamp, path };
41-
}));
56+
}, CONCURRENCY);
57+
58+
// Filter out undefined entries (failed requests)
59+
const filteredVersions = versions.filter((version) => version !== undefined);
4260

4361
return {
4462
status: resp.status,
4563
contentType: resp.contentType,
46-
body: JSON.stringify(promises),
64+
body: JSON.stringify(filteredVersions),
4765
};
4866
}

0 commit comments

Comments
 (0)