log query performance and reduce full item resolver calls

This commit is contained in:
keyan 2022-03-31 13:05:11 -05:00
parent 9823aedd75
commit d938596efe
2 changed files with 15 additions and 3 deletions

View File

@ -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

View File

@ -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 }) => {