-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
51 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
import './lib/globals'; | ||
import './lib/data/itemAliases'; | ||
import './lib/data/trophies'; | ||
import './lib/crons'; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { isMainThread } from 'node:worker_threads'; | ||
import { TSRedis } from '@oldschoolgg/toolkit/dist/lib/TSRedis'; | ||
import { PrismaClient } from '@prisma/client'; | ||
|
||
import { production } from '../config'; | ||
import { globalConfig } from './constants'; | ||
|
||
declare global { | ||
var prisma: PrismaClient; | ||
var redis: TSRedis; | ||
} | ||
|
||
function makePrismaClient(): PrismaClient { | ||
if (!production && !process.env.TEST) console.log('Making prisma client...'); | ||
if (!isMainThread && !process.env.TEST) { | ||
throw new Error('Prisma client should only be created on the main thread.'); | ||
} | ||
|
||
return new PrismaClient({ | ||
log: [ | ||
{ | ||
emit: 'event', | ||
level: 'query' | ||
} | ||
] | ||
}); | ||
} | ||
// biome-ignore lint/suspicious/noRedeclare: <explanation> | ||
const prisma = global.prisma || makePrismaClient(); | ||
global.prisma = prisma; | ||
|
||
function makeRedisClient(): TSRedis { | ||
if (!production && !process.env.TEST) console.log('Making Redis client...'); | ||
if (!isMainThread && !process.env.TEST) { | ||
throw new Error('Redis client should only be created on the main thread.'); | ||
} | ||
return new TSRedis({ mocked: !globalConfig.redisPort, port: globalConfig.redisPort }); | ||
} | ||
// biome-ignore lint/suspicious/noRedeclare: <explanation> | ||
const redis = global.redis || makeRedisClient(); | ||
global.redis = redis; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters