limit related queries in me query for SSR
This commit is contained in:
parent
934c5021a9
commit
dc44764008
@ -167,10 +167,11 @@ export default {
|
|||||||
return getItem(user, { id: user.bioId }, { models })
|
return getItem(user, { id: user.bioId }, { models })
|
||||||
},
|
},
|
||||||
hasInvites: async (user, args, { models }) => {
|
hasInvites: async (user, args, { models }) => {
|
||||||
const invite = await models.invite.findFirst({
|
const invites = await models.user.findUnique({
|
||||||
where: { userId: user.id }
|
where: { id: user.id }
|
||||||
})
|
}).invites({ take: 1 })
|
||||||
return !!invite
|
|
||||||
|
return invites.length > 0
|
||||||
},
|
},
|
||||||
hasNewNotes: async (user, args, { me, models }) => {
|
hasNewNotes: async (user, args, { me, models }) => {
|
||||||
const lastChecked = user.checkedNotesAt || new Date(0)
|
const lastChecked = user.checkedNotesAt || new Date(0)
|
||||||
|
@ -8,7 +8,7 @@ import models from './models'
|
|||||||
import { print } from 'graphql'
|
import { print } from 'graphql'
|
||||||
import lnd from './lnd'
|
import lnd from './lnd'
|
||||||
import search from './search'
|
import search from './search'
|
||||||
import { ME } from '../fragments/users'
|
import { ME_SSR } from '../fragments/users'
|
||||||
import { getPrice } from '../components/price'
|
import { getPrice } from '../components/price'
|
||||||
|
|
||||||
export default async function getSSRApolloClient (req, me = null) {
|
export default async function getSSRApolloClient (req, me = null) {
|
||||||
@ -66,7 +66,7 @@ export function getGetServerSideProps (query, variables = null, notFoundFunc, re
|
|||||||
}
|
}
|
||||||
|
|
||||||
const { data: { me } } = await client.query({
|
const { data: { me } } = await client.query({
|
||||||
query: ME
|
query: ME_SSR
|
||||||
})
|
})
|
||||||
|
|
||||||
const price = await getPrice()
|
const price = await getPrice()
|
||||||
|
@ -26,6 +26,28 @@ export const ME = gql`
|
|||||||
}
|
}
|
||||||
}`
|
}`
|
||||||
|
|
||||||
|
export const ME_SSR = gql`
|
||||||
|
{
|
||||||
|
me {
|
||||||
|
id
|
||||||
|
name
|
||||||
|
sats
|
||||||
|
stacked
|
||||||
|
freePosts
|
||||||
|
freeComments
|
||||||
|
tipDefault
|
||||||
|
bioId
|
||||||
|
upvotePopover
|
||||||
|
tipPopover
|
||||||
|
noteItemSats
|
||||||
|
noteEarning
|
||||||
|
noteAllDescendants
|
||||||
|
noteMentions
|
||||||
|
noteDeposits
|
||||||
|
noteInvites
|
||||||
|
}
|
||||||
|
}`
|
||||||
|
|
||||||
export const NAME_QUERY =
|
export const NAME_QUERY =
|
||||||
gql`
|
gql`
|
||||||
query nameAvailable($name: String!) {
|
query nameAvailable($name: String!) {
|
||||||
|
@ -19,7 +19,7 @@ const apolloServer = new ApolloServer({
|
|||||||
return (error, result) => {
|
return (error, result) => {
|
||||||
const end = process.hrtime.bigint()
|
const end = process.hrtime.bigint()
|
||||||
const ms = (end - start) / 1000000n
|
const ms = (end - start) / 1000000n
|
||||||
if (ms > 20) {
|
if (ms > 20 && info.parentType.name !== 'User') {
|
||||||
console.log(`Field ${info.parentType.name}.${info.fieldName} took ${ms}ms`)
|
console.log(`Field ${info.parentType.name}.${info.fieldName} took ${ms}ms`)
|
||||||
}
|
}
|
||||||
if (error) {
|
if (error) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user