Skip to content

refactor(api): extract hardcoded delay and limit constants in handlers#828

Open
NewCoder3294 wants to merge 1 commit intokoala73:mainfrom
NewCoder3294:refactor/handler-delay-constants
Open

refactor(api): extract hardcoded delay and limit constants in handlers#828
NewCoder3294 wants to merge 1 commit intokoala73:mainfrom
NewCoder3294:refactor/handler-delay-constants

Conversation

@NewCoder3294
Copy link
Contributor

Summary

Replace inline magic numbers with named UPPER_SNAKE_CASE constants across 10 server handler files. No logic changes -- only extraction of numeric literals into documented module-level constants for clarity and maintainability.

Constants extracted

server/worldmonitor/military/v1/get-aircraft-details-batch.ts

Constant Value Purpose
MAX_BATCH_SIZE 10 Max ICAO24 identifiers per batch request
FETCH_DELAY_MS 100 Delay between sequential Wingbits API fetches
WINGBITS_TIMEOUT_MS 10_000 Timeout for individual Wingbits API requests
AIRCRAFT_CACHE_TTL 24 * 60 * 60 Cache TTL for aircraft details (24 hours)

server/worldmonitor/positive-events/v1/list-positive-geo-events.ts

Constant Value Purpose
GDELT_QUERY_DELAY_MS 500 Delay between sequential GDELT queries
GDELT_MAX_RECORDS 75 Max records per GDELT GEO API request
GDELT_TIMEOUT_MS 10_000 Timeout for GDELT API requests
MIN_EVENT_COUNT 3 Minimum article count noise filter

server/worldmonitor/economic/v1/get-energy-capacity.ts

Constant Value Purpose
EIA_MAX_RESULTS 5000 Max rows from EIA capability endpoint
EIA_TIMEOUT_MS 15_000 Timeout for EIA API requests

server/worldmonitor/displacement/v1/get-displacement-summary.ts

Constant Value Purpose
UNHCR_PAGE_LIMIT 10_000 Max items per UNHCR Population API page
MAX_PAGE_GUARD 25 Safety cap on pagination page count
DEFAULT_FLOW_LIMIT 50 Default number of refugee flow corridors

server/worldmonitor/unrest/v1/list-unrest-events.ts

Constant Value Purpose
GDELT_MAX_RECORDS 250 Max records per GDELT GEO API request
GDELT_TIMEOUT_MS 10_000 Timeout for GDELT API requests
MIN_REPORT_COUNT 5 Minimum report count noise filter
HIGH_CONFIDENCE_THRESHOLD 20 Report count above which confidence is HIGH

server/worldmonitor/infrastructure/v1/list-internet-outages.ts

Constant Value Purpose
OUTAGE_QUERY_LIMIT 50 Max outage annotations from Cloudflare Radar
MAX_ASN_DETAILS 2 Max ASN detail entries per outage

server/worldmonitor/conflict/v1/get-humanitarian-summary.ts

Constant Value Purpose
HAPI_QUERY_LIMIT 1000 Max records per HAPI conflict-events query
HAPI_TIMEOUT_MS 15_000 Timeout for HAPI API requests

server/worldmonitor/infrastructure/v1/record-baseline-snapshot.ts

Constant Value Purpose
MAX_BATCH_UPDATES 20 Max baseline updates processed per request

server/worldmonitor/economic/v1/get-energy-prices.ts

Constant Value Purpose
EIA_PRICE_HISTORY_LENGTH 2 Recent data points for price comparison
EIA_PRICE_TIMEOUT_MS 10_000 Timeout for EIA API requests

server/worldmonitor/research/v1/list-hackernews-items.ts

Constant Value Purpose
DEFAULT_PAGE_SIZE 30 Default number of HN stories per page
HN_IDS_TIMEOUT_MS 10_000 Timeout for fetching story IDs list
HN_ITEM_TIMEOUT_MS 5_000 Timeout for fetching individual story items

Test plan

  • TypeScript type-check passes (tsc --noEmit)
  • Verify no behavioral changes by running existing test suite
  • Spot-check a few endpoints to confirm responses are identical

🤖 Generated with Claude Code

Replace inline magic numbers with named UPPER_SNAKE_CASE constants
across 10 server handler files. No logic changes — only extraction
of numeric literals into documented module-level constants.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@vercel
Copy link

vercel bot commented Mar 2, 2026

@NewCoder3294 is attempting to deploy a commit to the Elie Team on Vercel.

A member of the Team first needs to authorize it.

@koala73 koala73 added Not Ready to Merge PR has conflicts, failing checks, or needs work Low Value Trivial, unnecessary, or not aligned with project needs labels Mar 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Low Value Trivial, unnecessary, or not aligned with project needs Not Ready to Merge PR has conflicts, failing checks, or needs work

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants