pull down to refresh

When there's a userId, does this query actually pull up anything? And is the creation date after now? Maybe I'm reading this wrong.
const dayFragment = userId ? Prisma.sql`(now() AT TIME ZONE 'America/Chicago')::date` : Prisma.sql`(now() AT TIME ZONE 'America/Chicago' - interval '1 day')::date` ... WHERE ("Invoice"."created_at" AT TIME ZONE 'UTC' AT TIME ZONE 'America/Chicago')::date >= ${dayFragment} ...
I don't understand the !userId part there, either.
But I notice all horses and guns are gone today.
@koob Why is worker/streak.js function checkStream() only called for hats?
reply
Or, rather, is it related to the seed job only doing hats (like, after a restart)?
./worker/streak.js:export async function checkStreak ({ data: { id, type = 'COWBOY_HAT' }, models }) { ./docker/db/seed.sql: INSERT INTO pgboss.job (name, data, priority) VALUES ('checkStreak', jsonb_build_object('id', NEW.id), -1);
Or how msat reduction triggers it
./docker/db/seed.sql:CREATE TRIGGER user_streak AFTER UPDATE ON public.users FOR EACH ROW WHEN ((new.msats < old.msats)) EXECUTE FUNCTION public.user_streak_check(); INSERT INTO pgboss.job (name, data, priority) VALUES ('checkStreak', jsonb_build_object('id', NEW.id), -1);
reply
23 sats \ 0 replies \ @ek 17 Oct
It's called for every streak, the type = 'COWBOW_HAT' only means that's the default streak that we're checking (for backwards compatibility reasons)
reply
23 sats \ 4 replies \ @ek 17 Oct
The ::date at the end casts the current timestamp to a date so it's actually the current date that we're using, not the current timestamp in which case you would be right:
stackernews=# SELECT (now() AT TIME ZONE 'America/Chicago')::date; timezone ------------ 2024-10-17 (1 row)
So the query pulls all invoices that were created today.
reply
So it's not a rolling 24h window, but resets on midnight Chicago time? And anon gets an extra day?
reply
33 sats \ 2 replies \ @ek 17 Oct
Yes, it's not rolling but it checks every midnight Chicago time if the streak is still valid. This means you can gain a streak at any time but you can only lose it at midnight.
And anon gets an extra day?
No, this function is used in two different contexts. In the first context, it's called to check if a user has a new streak. We pass userId in that case and then we check for their zaps from today.
In the other context, it's called without userId to check if streaks have been lost. This means we want to get zaps from all users from the previous day since remember, we run this function at midnight which basically means slightly after midnight. Therefore, we need - interval '1 day' in that case.
Could have been communicated better through the code but it works.
reply
Thank you for the explanation!
reply
28 sats \ 0 replies \ @ek 17 Oct
No worries, glad people are interested in the code
reply
11 sats \ 4 replies \ @chess 16 Oct bot
reply
~ $ sudo reboot
reply
just messing around with comment editing after 10 minutes
edit: Comment edited 15 minutes after creation.
reply
27 sats \ 1 reply \ @ek 17 Oct
wdym with "comment edited 15 minutes after creation"?
reply
yes!
To replicate the issue, try clicking 'edit' within the 10-minute window but don't confirm any changes during that time. I waited an extra 5 minutes after the 10-minute mark and it still recorded. I only discovered this by chance when I had to step away to use the bathroom mid-edit.
reply