Skip to content
This repository was archived by the owner on Feb 9, 2026. It is now read-only.

fix: address deployment memory issues#39

Merged
fabio-nettis merged 2 commits intomainfrom
fix/database
Apr 15, 2024
Merged

fix: address deployment memory issues#39
fabio-nettis merged 2 commits intomainfrom
fix/database

Conversation

@fabio-nettis
Copy link
Member

Description

Recent deployment monitoring has shown that we waste a lot of unnecessary memory by not properly re-using a single Prisma instance but creating a new one for each route handler. Following fix has been implemented:

// utils/database.ts

import { PrismaClient } from "@prisma/client";

const globalForPrisma = globalThis as unknown as { db: PrismaClient };

// prevent hot reloading from creating new instances of PrismaClient
export const db = globalForPrisma.db || new PrismaClient();
if (process.env.NODE_ENV !== "production") globalForPrisma.db = db;

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

@fabio-nettis fabio-nettis added the feature Optimizes or introduces a feature label Apr 15, 2024
@fabio-nettis fabio-nettis merged commit ae29634 into main Apr 15, 2024
@fabio-nettis fabio-nettis deleted the fix/database branch April 15, 2024 14:28
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

feature Optimizes or introduces a feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant