Skip to content

refactor: Extract magic numbers to named constants #31

@greynewell

Description

@greynewell

Problem

The codebase has hard-coded magic numbers that appear multiple times and lack clear meaning:

Examples

1. ZIP cleanup timeout (appears twice)

// src/server.ts:84
await cleanupOldZips(24 * 60 * 60 * 1000);

// src/utils/zip-repository.ts
export async function cleanupOldZips(maxAgeMs: number = 24 * 60 * 60 * 1000)

2. ZIP size limit

// src/utils/zip-repository.ts
const MAX_ZIP_SIZE = 50 * 1024 * 1024; // 50MB

Proposed Solution

Create a constants file:

// src/constants.ts
export const ZIP_CLEANUP_AGE_MS = 24 * 60 * 60 * 1000; // 24 hours
export const MAX_ZIP_SIZE_BYTES = 50 * 1024 * 1024; // 50MB
export const DEFAULT_QUERY_LIMIT = 200;
export const MAX_NEIGHBORHOOD_DEPTH = 3;

Then import and use:

import { ZIP_CLEANUP_AGE_MS } from './constants';

await cleanupOldZips(ZIP_CLEANUP_AGE_MS);

Benefits

  • Single source of truth
  • Easier to adjust limits
  • More maintainable
  • Self-documenting

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions