From 077ae79e80886bb347d728f23ced0fe34d24db59 Mon Sep 17 00:00:00 2001 From: Luke Vella Date: Sun, 23 Mar 2025 14:34:40 +0000 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Deprecating=20touch=20beac?= =?UTF-8?q?on?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/docs/faq.mdx | 5 +++-- .../[locale]/invite/[urlId]/invite-page.tsx | 2 -- .../app/[locale]/poll/[urlId]/admin-page.tsx | 2 -- .../delete-inactive-polls/route.ts | 9 +++------ .../src/components/poll/use-touch-beacon.ts | 19 ------------------- apps/web/src/trpc/routers/polls.ts | 3 +++ packages/database/prisma/schema.prisma | 2 +- 7 files changed, 10 insertions(+), 32 deletions(-) delete mode 100644 apps/web/src/components/poll/use-touch-beacon.ts diff --git a/apps/docs/faq.mdx b/apps/docs/faq.mdx index a649c18d5..ceb1e5804 100644 --- a/apps/docs/faq.mdx +++ b/apps/docs/faq.mdx @@ -24,8 +24,9 @@ description: "Frequently asked questions about Rallly." - Polls are automatically deleted when all date options are in the past AND the - poll has not been accessed for over 30 days. This does not apply to Pro users. + For free users, polls are automatically marked for deletion when all date + options are more than 30 days in the past. For Pro users, polls are never + automatically deleted. diff --git a/apps/web/src/app/[locale]/invite/[urlId]/invite-page.tsx b/apps/web/src/app/[locale]/invite/[urlId]/invite-page.tsx index f8be656a7..48d0cba31 100644 --- a/apps/web/src/app/[locale]/invite/[urlId]/invite-page.tsx +++ b/apps/web/src/app/[locale]/invite/[urlId]/invite-page.tsx @@ -8,7 +8,6 @@ import { PollFooter } from "@/components/poll/poll-footer"; import { PollHeader } from "@/components/poll/poll-header"; import { ResponsiveResults } from "@/components/poll/responsive-results"; import { ScheduledEvent } from "@/components/poll/scheduled-event"; -import { useTouchBeacon } from "@/components/poll/use-touch-beacon"; import { VotingForm } from "@/components/poll/voting-form"; import { Trans } from "@/components/trans"; import { useUser } from "@/components/user-provider"; @@ -51,7 +50,6 @@ const GoToApp = () => { }; export function InvitePage() { - useTouchBeacon(); return (
diff --git a/apps/web/src/app/[locale]/poll/[urlId]/admin-page.tsx b/apps/web/src/app/[locale]/poll/[urlId]/admin-page.tsx index 84f341609..3966c5183 100644 --- a/apps/web/src/app/[locale]/poll/[urlId]/admin-page.tsx +++ b/apps/web/src/app/[locale]/poll/[urlId]/admin-page.tsx @@ -5,14 +5,12 @@ import { PollFooter } from "@/components/poll/poll-footer"; import { PollHeader } from "@/components/poll/poll-header"; import { ResponsiveResults } from "@/components/poll/responsive-results"; import { ScheduledEvent } from "@/components/poll/scheduled-event"; -import { useTouchBeacon } from "@/components/poll/use-touch-beacon"; import { VotingForm } from "@/components/poll/voting-form"; import { GuestPollAlert } from "./guest-poll-alert"; import { UnsubscribeAlert } from "./unsubscribe-alert"; export function AdminPage() { - useTouchBeacon(); return (
diff --git a/apps/web/src/app/api/house-keeping/delete-inactive-polls/route.ts b/apps/web/src/app/api/house-keeping/delete-inactive-polls/route.ts index 6fbdfe640..b3e172820 100644 --- a/apps/web/src/app/api/house-keeping/delete-inactive-polls/route.ts +++ b/apps/web/src/app/api/house-keeping/delete-inactive-polls/route.ts @@ -4,8 +4,8 @@ import { NextResponse } from "next/server"; import { checkApiAuthorization } from "@/utils/api-auth"; /** - * Marks inactive polls as deleted. Polls are inactive if they have not been - * touched in the last 30 days and all dates are in the past. + * Marks inactive polls as deleted. Polls are inactive if the last option is more than + * 30 days in the past. * Only marks polls as deleted if they belong to users without an active subscription * or if they don't have a user associated with them. */ @@ -16,14 +16,11 @@ export async function POST() { // Mark inactive polls as deleted in a single query const { count: markedDeleted } = await prisma.poll.updateMany({ where: { - touchedAt: { - lt: new Date(Date.now() - 30 * 24 * 60 * 60 * 1000), // 30 days ago - }, deleted: false, options: { none: { startTime: { - gt: new Date(), + lt: new Date(Date.now() - 30 * 24 * 60 * 60 * 1000), }, }, }, diff --git a/apps/web/src/components/poll/use-touch-beacon.ts b/apps/web/src/components/poll/use-touch-beacon.ts deleted file mode 100644 index 0085e183e..000000000 --- a/apps/web/src/components/poll/use-touch-beacon.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { useMount } from "react-use"; - -import { usePoll } from "@/contexts/poll"; -import { trpc } from "@/trpc/client"; - -/** - * Touching a poll updates a column with the current date. This information is used to - * find polls that haven't been accessed for some time so that they can be deleted by house keeping. - */ -export const useTouchBeacon = () => { - const poll = usePoll(); - const touchMutation = trpc.polls.touch.useMutation({ - meta: { doNotInvalidate: true }, - }); - - useMount(() => { - touchMutation.mutate({ pollId: poll.id }); - }); -}; diff --git a/apps/web/src/trpc/routers/polls.ts b/apps/web/src/trpc/routers/polls.ts index 52d687bba..07cd93a6e 100644 --- a/apps/web/src/trpc/routers/polls.ts +++ b/apps/web/src/trpc/routers/polls.ts @@ -365,6 +365,9 @@ export const polls = router({ data: { deleted: true, deletedAt: new Date() }, }); }), + /** + * @deprecated + */ touch: publicProcedure .input( z.object({ diff --git a/packages/database/prisma/schema.prisma b/packages/database/prisma/schema.prisma index 0748a764d..9e94eaf68 100644 --- a/packages/database/prisma/schema.prisma +++ b/packages/database/prisma/schema.prisma @@ -151,7 +151,7 @@ model Poll { status PollStatus @default(live) deleted Boolean @default(false) deletedAt DateTime? @map("deleted_at") - touchedAt DateTime @default(now()) @map("touched_at") + touchedAt DateTime @default(now()) @map("touched_at") // @deprecated participantUrlId String @unique @map("participant_url_id") adminUrlId String @unique @map("admin_url_id") eventId String? @unique @map("event_id")