log query performance and reduce full item resolver calls
This commit is contained in:
parent
9823aedd75
commit
d938596efe
|
@ -1,7 +1,16 @@
|
|||
import { PrismaClient } from '@prisma/client'
|
||||
|
||||
global.prisma ||= new PrismaClient({
|
||||
log: ['warn', 'error']
|
||||
})
|
||||
if (!global.prisma) {
|
||||
global.prisma = new PrismaClient({
|
||||
log: [{ level: 'query', emit: 'event' }, 'warn', 'error']
|
||||
})
|
||||
global.prisma.$on('query', (e) => {
|
||||
if (e.duration > 50) {
|
||||
console.log('Query: ' + e.query)
|
||||
console.log('Params: ' + e.params)
|
||||
console.log('Duration: ' + e.duration + 'ms')
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export default global.prisma
|
||||
|
|
|
@ -672,6 +672,9 @@ export default {
|
|||
return count || 0
|
||||
},
|
||||
comments: async (item, args, { models }) => {
|
||||
if (item.comments) {
|
||||
return item.comments
|
||||
}
|
||||
return comments(models, item.id, 'hot')
|
||||
},
|
||||
sats: async (item, args, { models }) => {
|
||||
|
|
Loading…
Reference in New Issue