···41414242// NOTE: this router is used on status pages only - do not confuse with the page router which is used in the dashboard for the config
43434444+/**
4545+ * Right now, we do not allow workspaces to have a custom lookback period.
4646+ * If we decide to allow this in the future, we should move this to the database.
4747+ */
4848+const WORKSPACES =
4949+ process.env.WORKSPACES_LOOKBACK_30?.split(",").map(Number) || [];
5050+4451export const statusPageRouter = createTRPCRouter({
4552 get: publicProcedure
4653 .input(
···455462 });
456463 }
457464465465+ const lookbackPeriod = WORKSPACES.includes(_page.workspaceId ?? 0)
466466+ ? 30
467467+ : 45;
468468+458469 return monitors.map((m) => {
459470 const monitorId = m.monitor.id.toString();
460471 const events = getEvents({
···466477 const rawData = statusDataByMonitorId.get(monitorId) || [];
467478 const filledData =
468479 process.env.NOOP_UPTIME === "true"
469469- ? fillStatusDataFor45DaysNoop({ errorDays: [], degradedDays: [] })
470470- : fillStatusDataFor45Days(rawData, monitorId);
480480+ ? fillStatusDataFor45DaysNoop({
481481+ errorDays: [],
482482+ degradedDays: [],
483483+ lookbackPeriod,
484484+ })
485485+ : fillStatusDataFor45Days(rawData, monitorId, lookbackPeriod);
471486 const processedData = setDataByType({
472487 events,
473488 data: filledData,
+5-2
packages/api/src/router/statusPage.utils.ts
···1717export function fillStatusDataFor45Days(
1818 data: Array<StatusData>,
1919 monitorId: string,
2020+ lookbackPeriod = 45,
2021): Array<StatusData> {
2122 const result = [];
2223 const dataByDay = new Map();
···29303031 // Generate all 45 days from today backwards
3132 const now = new Date();
3232- for (let i = 0; i < 45; i++) {
3333+ for (let i = 0; i < lookbackPeriod; i++) {
3334 const date = new Date(now);
3435 date.setUTCDate(date.getUTCDate() - i);
3536 date.setUTCHours(0, 0, 0, 0); // Set to start of day in UTC
···6667export function fillStatusDataFor45DaysNoop({
6768 errorDays,
6869 degradedDays,
7070+ lookbackPeriod = 45,
6971}: {
7072 errorDays: number[];
7173 degradedDays: number[];
7474+ lookbackPeriod?: number;
7275}): Array<StatusData> {
7376 const issueDays = [...errorDays, ...degradedDays];
7477 const data: StatusData[] = Array.from({ length: 45 }, (_, i) => {
···8184 monitorId: "1",
8285 };
8386 });
8484- return fillStatusDataFor45Days(data, "1");
8787+ return fillStatusDataFor45Days(data, "1", lookbackPeriod);
8588}
86898790type Event = {