Skip to content

Commit

Permalink
fix(network): add caching for fetching connections
Browse files Browse the repository at this point in the history
  • Loading branch information
dev-737 committed Nov 18, 2023
1 parent 16682aa commit 4f05938
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 4 deletions.
12 changes: 12 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"type": "module",
"dependencies": {
"@prisma/client": "^5.6.0",
"@prisma/extension-accelerate": "^0.6.2",
"@sentry/node": "^7.80.1",
"@translate-tools/core": "^1.0.0",
"common-tags": "^1.8.2",
Expand Down
2 changes: 1 addition & 1 deletion prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ generator client {

datasource db {
provider = "mongodb"
url = env("MONGODB_URI")
url = env("DATABASE_URL")
}

type MessageDataChannelAndMessageIds {
Expand Down
4 changes: 2 additions & 2 deletions src/managers/NetworkManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -625,11 +625,11 @@ export default class NetworkManager extends Factory {

// TODO: Add Error handlers for these
public async fetchHubNetworks(where: { hubId?: string; hubName?: string }) {
return await db.connectedList.findMany({ where });
return await db.connectedList.findMany({ where, cacheStrategy: { ttl: 60 } });
}

public async fetchConnection(where: Prisma.connectedListWhereInput) {
return await db.connectedList.findFirst({ where });
return await db.connectedList.findFirst({ where, cacheStrategy: { ttl: 60 } });
}

async updateConnection(
Expand Down
3 changes: 2 additions & 1 deletion src/utils/Db.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { PrismaClient } from '@prisma/client';
import { withAccelerate } from '@prisma/extension-accelerate';

const db = new PrismaClient();
const db = new PrismaClient().$extends(withAccelerate());

export default db;

0 comments on commit 4f05938

Please sign in to comment.