From d2697477a004bae6a9c048e1a807d821dc0bc0df Mon Sep 17 00:00:00 2001 From: keyan Date: Mon, 23 Oct 2023 18:19:36 -0500 Subject: [PATCH] saner lastSeenAt checking --- api/resolvers/user.js | 24 +++++++++++++++++------- api/ssrApollo.js | 5 +---- api/typeDefs/user.js | 2 +- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/api/resolvers/user.js b/api/resolvers/user.js index de2554a0..282678b3 100644 --- a/api/resolvers/user.js +++ b/api/resolvers/user.js @@ -102,14 +102,11 @@ async function authMethods (user, args, { models, me }) { export default { Query: { - me: async (parent, { skipUpdate }, { models, me }) => { + me: async (parent, args, { models, me }) => { if (!me?.id) { return null } - if (!skipUpdate) { - models.user.update({ where: { id: me.id }, data: { lastSeenAt: new Date() } }).catch(console.error) - } return await models.user.findUnique({ where: { id: me.id } }) }, settings: async (parent, args, { models, me }) => { @@ -291,7 +288,14 @@ export default { return true } - const foundNotes = () => models.user.update({ where: { id: me.id }, data: { foundNotesAt: new Date() } }).catch(console.error) + const foundNotes = () => + models.user.update({ + where: { id: me.id }, + data: { + foundNotesAt: new Date(), + lastSeenAt: new Date() + } + }).catch(console.error) // check if any votes have been cast for them since checkedNotesAt if (user.noteItemSats) { @@ -483,8 +487,14 @@ export default { } } - // since they don't have notifications, we can update their checkedNotesAt - await models.user.update({ where: { id: me.id }, data: { checkedNotesAt: new Date() } }) + // update checkedNotesAt to prevent rechecking same time period + models.user.update({ + where: { id: me.id }, + data: { + checkedNotesAt: new Date(), + lastSeenAt: new Date() + } + }).catch(console.error) return false }, diff --git a/api/ssrApollo.js b/api/ssrApollo.js index 74b55523..19afb2db 100644 --- a/api/ssrApollo.js +++ b/api/ssrApollo.js @@ -75,10 +75,7 @@ export function getGetServerSideProps ( const client = await getSSRApolloClient({ req, res }) - const { data: { me } } = await client.query({ - query: ME, - variables: { skipUpdate: true } - }) + const { data: { me } } = await client.query({ query: ME }) if (authRequired && !me) { const callback = process.env.PUBLIC_URL + req.url diff --git a/api/typeDefs/user.js b/api/typeDefs/user.js index 731cfa9f..d9184d0e 100644 --- a/api/typeDefs/user.js +++ b/api/typeDefs/user.js @@ -2,7 +2,7 @@ import { gql } from 'graphql-tag' export default gql` extend type Query { - me(skipUpdate: Boolean): User + me: User settings: User user(name: String!): User users: [User!]