♻️ Deprecating touch beacon

This commit is contained in:
Luke Vella 2025-03-23 14:34:40 +00:00
parent 6b914610d9
commit 077ae79e80
No known key found for this signature in database
GPG key ID: 469CAD687F0D784C
7 changed files with 10 additions and 32 deletions

View file

@ -24,8 +24,9 @@ description: "Frequently asked questions about Rallly."
</Accordion>
<Accordion title="How long will Rallly keep my poll?">
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.
</Accordion>
<Accordion title="Can I limit the number of participants that can vote for an option?">

View file

@ -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 (
<div className="mx-auto max-w-4xl space-y-3 p-3 lg:space-y-4 lg:px-4 lg:py-8">
<PollHeader />

View file

@ -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 (
<div className="space-y-3 lg:space-y-4">
<UnsubscribeAlert />

View file

@ -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),
},
},
},

View file

@ -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 });
});
};

View file

@ -365,6 +365,9 @@ export const polls = router({
data: { deleted: true, deletedAt: new Date() },
});
}),
/**
* @deprecated
*/
touch: publicProcedure
.input(
z.object({

View file

@ -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")