Skip to content

Refactor getCommitsStream to use async generators correctly #24

Description

@SHAURYASANYAL3

🛑 The Problem

Right now, if we fetch a repository with 50,000 commits, we attempt to download all 50,000 into a single JavaScript array in memory before inserting them into Postgres. This will cause Node.js to trigger a V8 Fatal Error (Heap Out of Memory) and crash the server.

💡 The Solution

We must stream the data. We need to refactor the ingestion logic to use Async Generators, inserting data into Postgres in chunks of 100, and immediately letting the garbage collector free the memory before fetching the next page.

🛠️ Implementation Details

  1. Change the fetch function to return an AsyncGenerator.
  2. Use for await (const response of octokit.paginate.iterator(...)).
  3. Inside the loop, extract the 100 commits from the current page.
  4. Execute a bulk INSERT into Drizzle.
  5. yield a progress update (e.g., total processed).
  6. The loop continues to the next page, allowing V8 to garbage collect the previous page's JSON.

✅ Acceptance Criteria

  • The memory profile remains flat (under 200MB) regardless of repository size.
  • Data is inserted incrementally, so users can see progress in the UI.

Ready to tackle this? Comment .take below to get automatically assigned!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions