a few perf enhancements + gql slowlogs

This commit is contained in:
keyan 2022-04-28 13:11:05 -05:00
parent 8e0aaab161
commit 934c5021a9
5 changed files with 36 additions and 16 deletions

View File

@ -167,10 +167,10 @@ export default {
return getItem(user, { id: user.bioId }, { models })
},
hasInvites: async (user, args, { models }) => {
const anInvite = await models.invite.findFirst({
const invite = await models.invite.findFirst({
where: { userId: user.id }
})
return !!anInvite
return !!invite
},
hasNewNotes: async (user, args, { me, models }) => {
const lastChecked = user.checkedNotesAt || new Date(0)
@ -183,7 +183,6 @@ export default {
JOIN "ItemAct" on "ItemAct"."itemId" = "Item".id
WHERE "ItemAct"."userId" <> $1
AND "ItemAct".created_at > $2
AND "ItemAct".act <> 'BOOST'
AND "Item"."userId" = $1
LIMIT 1`, user.id, lastChecked)
if (votes.length > 0) {

View File

@ -47,6 +47,7 @@ export default gql`
hasInvites: Boolean!
tipDefault: Int!
bio: Item
bioId: Int
sats: Int!
upvotePopover: Boolean!
tipPopover: Boolean!

View File

@ -48,7 +48,7 @@ export default function Header ({ sub }) {
<Link href={'/' + me?.name} passHref>
<NavDropdown.Item>
profile
{me && !me.bio &&
{me && !me.bioId &&
<div className='p-1 d-inline-block bg-secondary ml-1'>
<span className='invisible'>{' '}</span>
</div>}
@ -78,7 +78,7 @@ export default function Header ({ sub }) {
<NavDropdown.Divider />
<NavDropdown.Item onClick={() => signOut({ callbackUrl: '/' })}>logout</NavDropdown.Item>
</NavDropdown>
{me && !me.bio &&
{me && !me.bioId &&
<span className='position-absolute p-1 bg-secondary' style={{ top: '5px', right: '0px' }}>
<span className='invisible'>{' '}</span>
</span>}

View File

@ -13,9 +13,7 @@ export const ME = gql`
freeComments
hasNewNotes
tipDefault
bio {
id
}
bioId
hasInvites
upvotePopover
tipPopover

View File

@ -6,16 +6,32 @@ import typeDefs from '../../api/typeDefs'
import { getSession } from 'next-auth/client'
import search from '../../api/search'
const plugin = {
serverWillStart (ctx) {
console.log('gql server starting up')
}
}
const apolloServer = new ApolloServer({
typeDefs,
resolvers,
plugins: [plugin],
plugins: [{
requestDidStart (initialRequestContext) {
return {
executionDidStart (executionRequestContext) {
return {
willResolveField ({ source, args, context, info }) {
const start = process.hrtime.bigint()
return (error, result) => {
const end = process.hrtime.bigint()
const ms = (end - start) / 1000000n
if (ms > 20) {
console.log(`Field ${info.parentType.name}.${info.fieldName} took ${ms}ms`)
}
if (error) {
console.log(`It failed with ${error}`)
}
}
}
}
}
}
}
}],
context: async ({ req }) => {
const session = await getSession({ req })
return {
@ -29,4 +45,10 @@ const apolloServer = new ApolloServer({
}
})
module.exports = apolloServer.start().then(() => apolloServer.createHandler({ path: '/api/graphql' }))
export const config = {
api: {
bodyParser: false
}
}
export default apolloServer.createHandler({ path: '/api/graphql' })