set 6 month retention for hobby users
Some checks are pending
Node.js CI / build (postgresql, 18.18, 10) (push) Waiting to run

This commit is contained in:
Francis Cao 2025-12-17 13:28:34 -08:00
parent b75c15dc43
commit 37b6194c5f
2 changed files with 23 additions and 1 deletions

View file

@ -38,3 +38,15 @@ export async function fetchSession(websiteId: string, sessionId: string): Promis
return session;
}
export async function fetchAccount(websiteId: string) {
let account = null;
const cache = await redis.client.get(`cache:website:${websiteId}`);
if (cache) {
account = await redis.client.get(`account:${cache.account_id}`);
}
return account;
}

View file

@ -1,8 +1,9 @@
import { startOfMonth, subMonths } from 'date-fns';
import { z } from 'zod';
import { checkAuth } from '@/lib/auth';
import { DEFAULT_PAGE_SIZE, FILTER_COLUMNS } from '@/lib/constants';
import { getAllowedUnits, getMinimumUnit, maxDate, parseDateRange } from '@/lib/date';
import { fetchWebsite } from '@/lib/load';
import { fetchAccount, fetchWebsite } from '@/lib/load';
import { filtersArrayToObject } from '@/lib/params';
import { badRequest, unauthorized } from '@/lib/response';
import type { QueryFilters } from '@/lib/types';
@ -82,6 +83,15 @@ export function getRequestFilters(query: Record<string, any>) {
export async function setWebsiteDate(websiteId: string, data: Record<string, any>) {
const website = await fetchWebsite(websiteId);
const cloudMode = !!process.env.CLOUD_MODE;
if (cloudMode) {
const account = await fetchAccount(websiteId);
if (!account?.hasSubscription) {
data.startDate = maxDate(data.startDate, startOfMonth(subMonths(new Date(), 6)));
}
}
if (website?.resetAt) {
data.startDate = maxDate(data.startDate, new Date(website?.resetAt));