Skip to content

Overloaded API Handlers #1605

@Jhonattan2121

Description

@Jhonattan2121

The fetchDirectoryData function is extremely large and handles multiple types of queries (token holders, Farcaster channels, CSVs) and complex logic within a single API handler.
This violates the "Single Responsibility Principle".

Impact

  • Scalability: The API route becomes a bottleneck.
  • Readability: It is difficult to understand the flow of the request.
  • Error Handling: With so much logic in one place, error handling becomes generic and difficult to manage granularly.
  • Timeouts: Vercel/Next.js serverless functions have execution time limits. Performing heavy processing (like large CSV parsing or multiple external API calls) in one handler risks timeouts.

Recommendation

  1. Refactor the logic into separate service classes or functions (e.g., TokenService, FarcasterService).
  2. Create separate API endpoints for distinct operations if they are independent.
  3. For heavy tasks, consider using background jobs or edge functions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions