Skip to content

Commit 66dbe92

Browse files
committed
refactor(storage): extract S3 MaxKeys value to constant
Extracted hardcoded MaxKeys=1000 value to S3_MAX_KEYS_PER_REQUEST constant, addressing PR feedback from @mark-karnaukh-extern-sap. Changes: - Created src/server/Storage/constants.ts with S3_MAX_KEYS_PER_REQUEST constant - Updated objectRouter.ts to use the constant - Updated containerRouter.ts to use the constant - Updated comment in types/ceph.ts to reference the constant name This improves maintainability - the value is now defined in one place with proper documentation.
1 parent 6d8de1a commit 66dbe92

4 files changed

Lines changed: 16 additions & 4 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/**
2+
* Maximum number of keys returned per S3 ListObjects request.
3+
*
4+
* This is the AWS S3 maximum. We use this value as a performance trade-off:
5+
* - Fast response times for list operations
6+
* - Bucket metadata (count, size) are estimates for buckets > 1000 objects
7+
*
8+
* See: https://docs.aws.amazon.com/AmazonS3/latest/API/API_ListObjectsV2.html
9+
*/
10+
export const S3_MAX_KEYS_PER_REQUEST = 1000

apps/aurora-portal/src/server/Storage/routers/ceph/containerRouter.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
type Container,
1111
type S3Status,
1212
} from "../../types/ceph"
13+
import { S3_MAX_KEYS_PER_REQUEST } from "../../constants"
1314

1415
export const containerRouter = {
1516
status: cephProcedure.input(projectScopedInputSchema).query(async ({ ctx }): Promise<S3Status> => {
@@ -59,7 +60,7 @@ export const containerRouter = {
5960

6061
try {
6162
// List objects to get count, total size, and last modified
62-
// IMPORTANT: Using MaxKeys=1000 means these are ESTIMATES for buckets with >1000 objects:
63+
// IMPORTANT: Using S3_MAX_KEYS_PER_REQUEST means these are ESTIMATES for buckets with >1000 objects:
6364
// - count: Will be capped at 1000 (use KeyCount for actual count up to 1000)
6465
// - bytes: Only sums first 1000 objects
6566
// - last_modified: May miss newer objects beyond the first 1000
@@ -69,7 +70,7 @@ export const containerRouter = {
6970
const listObjResponse = await s3.send(
7071
new ListObjectsV2Command({
7172
Bucket: bucketName,
72-
MaxKeys: 1000,
73+
MaxKeys: S3_MAX_KEYS_PER_REQUEST,
7374
})
7475
)
7576

apps/aurora-portal/src/server/Storage/routers/ceph/objectRouter.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
type ListObjectsOutput,
1313
type S3ObjectDetails,
1414
} from "../../types/ceph"
15+
import { S3_MAX_KEYS_PER_REQUEST } from "../../constants"
1516
import { z } from "zod"
1617

1718
const deleteAllObjectsInputSchema = z.object({
@@ -126,7 +127,7 @@ export const objectRouter = {
126127
const listResponse = await s3.send(
127128
new ListObjectsV2Command({
128129
Bucket: containerName,
129-
MaxKeys: 1000, // S3 max per request
130+
MaxKeys: S3_MAX_KEYS_PER_REQUEST,
130131
ContinuationToken: continuationToken,
131132
})
132133
)

apps/aurora-portal/src/server/Storage/types/ceph.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export type Ec2CredentialWithSecret = z.infer<typeof ec2CredentialWithSecretSche
4040
* Includes count, bytes, and last_modified for consistent UI rendering
4141
*
4242
* IMPORTANT: count, bytes, and last_modified are ESTIMATES when buckets contain >1000 objects.
43-
* The list endpoint uses MaxKeys=1000 for performance, so these values are based on
43+
* The list endpoint uses S3_MAX_KEYS_PER_REQUEST for performance, so these values are based on
4444
* a sample of objects. For accurate counts, pagination would be needed (expensive).
4545
*/
4646
export const containerSchema = z.object({

0 commit comments

Comments
 (0)