From 6e4e4ff637e6a42a9d6188151cea79b1c4ef22a2 Mon Sep 17 00:00:00 2001 From: Soxasora Date: Mon, 23 Dec 2024 14:58:38 +0100 Subject: [PATCH] enhance: slimmer query, satsummary notification links to full satistics --- api/resolvers/notifications.js | 16 +++++++--------- components/notifications.js | 9 ++++----- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/api/resolvers/notifications.js b/api/resolvers/notifications.js index 5b2928d59..2c2f8130b 100644 --- a/api/resolvers/notifications.js +++ b/api/resolvers/notifications.js @@ -364,15 +364,13 @@ export default { if (meFull.noteSatSummary) { queries.push( - `(SELECT CONCAT('stats_', date_trunc('day', t))::text as id, - t AS "sortTime", - NULL as "earnedSats", - 'SatSummary' AS type + `(SELECT 'stats_' || date_trunc('day', t)::text as id, + t AS "sortTime", NULL as "earnedSats", 'SatSummary' AS type FROM user_stats_days - WHERE "user_stats_days"."id" = $1 + WHERE id = $1 AND t >= date_trunc('day', CURRENT_DATE - INTERVAL '1 day') AND t <= $2 - GROUP BY t, msats_stacked, msats_spent + GROUP BY t ORDER BY "sortTime" DESC LIMIT ${LIMIT})` ) @@ -505,14 +503,14 @@ export default { }, SatSummary: { date: async (n, args, { models }) => { - return new Date(n.id.replace('stats_', '')) + return new Date(n.sortTime) }, stacked: async (n, args, { me, models }) => { // msats_rewards is already counted in msats_stacked const [{ stacked }] = await models.$queryRaw` SELECT sum(msats_stacked) as stacked FROM user_stats_days WHERE id = ${Number(me.id)} - AND t = ${new Date(n.id.replace('stats_', ''))}::timestamp + AND t = ${n.sortTime}::timestamp ` return (stacked && msatsToSats(stacked)) || 0 }, @@ -521,7 +519,7 @@ export default { SELECT sum(msats_spent) as spent FROM user_stats_days WHERE id = ${Number(me.id)} - AND t = ${new Date(n.id.replace('stats_', ''))}::timestamp + AND t = ${n.sortTime}::timestamp ` return (spent && msatsToSats(spent)) || 0 } diff --git a/components/notifications.js b/components/notifications.js index a60b20502..39d3811ec 100644 --- a/components/notifications.js +++ b/components/notifications.js @@ -13,7 +13,7 @@ import HandCoin from '@/svgs/hand-coin-fill.svg' import UserAdd from '@/svgs/user-add-fill.svg' import { LOST_BLURBS, FOUND_BLURBS, UNKNOWN_LINK_REL } from '@/lib/constants' import CowboyHatIcon from '@/svgs/cowboy.svg' -import JusticeIcon from '@/svgs/scales-of-justice.svg' // WIP +import ScalesIcon from '@/svgs/scales-of-justice.svg' import BaldIcon from '@/svgs/bald.svg' import GunIcon from '@/svgs/revolver.svg' import HorseIcon from '@/svgs/horse.svg' @@ -164,7 +164,7 @@ const defaultOnClick = n => { if (type === 'Referral') return { href: '/referrals/month' } if (type === 'ReferralReward') return { href: '/referrals/month' } if (type === 'Streak') return {} - if (type === 'SatSummary') return {} + if (type === 'SatSummary') return { href: '/satistics?inc=stacked,spent' } if (type === 'TerritoryTransfer') return { href: `/~${n.sub.name}` } if (!n.item) return {} @@ -203,11 +203,10 @@ function Streak ({ n }) { ) } -function SatSummary ({ n }) { // WIP - // stacked and spent +function SatSummary ({ n }) { return (
-
+
you stacked {numWithUnits(n.stacked, { abbreviate: false })} and spent {numWithUnits(n.spent, { abbreviate: false })}
on {dayMonthYear(new Date(n.date))}