Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

update getEvents pagination limit

Steven Teya53847951679
diff --git a/apps/web/app/(ee)/api/events/route.ts b/apps/web/app/(ee)/api/events/route.ts
index 093df31f69..539ce75700 100644
--- a/apps/web/app/(ee)/api/events/route.ts
+++ b/apps/web/app/(ee)/api/events/route.ts
@@ -72,6 +72,7 @@ export const GET = withWorkspace(
userId: session.user.id,
});
+ console.time("getEvents");
const response = await getEvents({
...parsedParams,
event,
@@ -80,6 +81,7 @@ export const GET = withWorkspace(
folderIds,
folderId: folderId || "",
});
+ console.timeEnd("getEvents");
return NextResponse.json(response);
},
diff --git a/apps/web/app/api/analytics/route.ts b/apps/web/app/api/analytics/route.ts
index 6bff68ae7e..77a5fb6cb4 100644
--- a/apps/web/app/api/analytics/route.ts
+++ b/apps/web/app/api/analytics/route.ts
@@ -121,6 +121,7 @@ export const GET = withWorkspace(
const isDeprecatedClicksEndpoint =
oldEvent === "clicks" || oldType === "count";
+ console.time("getAnalytics");
const response = await getAnalytics({
...parsedParams,
event,
@@ -134,6 +135,7 @@ export const GET = withWorkspace(
dataAvailableFrom: programStartedAt ?? workspace.createdAt,
}),
});
+ console.timeEnd("getAnalytics");
return NextResponse.json(response);
},
diff --git a/apps/web/lib/zod/schemas/analytics.ts b/apps/web/lib/zod/schemas/analytics.ts
index f47cfc2291..0cf4754b4d 100644
--- a/apps/web/lib/zod/schemas/analytics.ts
+++ b/apps/web/lib/zod/schemas/analytics.ts
@@ -9,8 +9,8 @@ import {
import z from "@/lib/zod";
import {
CONTINENT_CODES,
+ DEFAULT_PAGINATION_LIMIT,
DUB_FOUNDING_DATE,
- PAGINATION_LIMIT,
capitalize,
formatDate,
} from "@dub/utils";
@@ -320,7 +320,7 @@ export const eventsFilterTB = analyticsFilterTB
.and(
z.object({
offset: z.coerce.number().default(0),
- limit: z.coerce.number().default(PAGINATION_LIMIT),
+ limit: z.coerce.number().default(DEFAULT_PAGINATION_LIMIT),
order: z.enum(["asc", "desc"]).default("desc"),
sortBy: z.enum(["timestamp"]).default("timestamp"),
}),
@@ -342,7 +342,10 @@ export const eventsQuerySchema = analyticsQuerySchema
"The type of event to retrieve analytics for. Defaults to 'clicks'.",
),
page: z.coerce.number().default(1),
- limit: z.coerce.number().default(PAGINATION_LIMIT),
+ limit: z.coerce
+ .number()
+ .max(1000, { message: "Max pagination limit is 1000 items per page." })
+ .default(DEFAULT_PAGINATION_LIMIT),
sortOrder,
sortBy: z
.enum(["timestamp"])
diff --git a/packages/ui/src/hooks/use-pagination.ts b/packages/ui/src/hooks/use-pagination.ts
index 1f0b431986..fe175c930a 100644
--- a/packages/ui/src/hooks/use-pagination.ts
+++ b/packages/ui/src/hooks/use-pagination.ts
@@ -1,4 +1,4 @@
-import { PAGINATION_LIMIT } from "@dub/utils";
+import { DEFAULT_PAGINATION_LIMIT } from "@dub/utils";
import { useEffect, useMemo } from "react";
import { useTablePagination } from "../table/use-table-pagination";
import { useRouterStuff } from "./use-router-stuff";
@@ -8,7 +8,7 @@ export type PaginationState = {
pageSize: number;
};
-export function usePagination(pageSize = PAGINATION_LIMIT) {
+export function usePagination(pageSize = DEFAULT_PAGINATION_LIMIT) {
const { searchParams, queryParams } = useRouterStuff();
const page = useMemo(
diff --git a/packages/utils/src/constants/misc.ts b/packages/utils/src/constants/misc.ts
index 445df4483c..aae02c88ed 100644
--- a/packages/utils/src/constants/misc.ts
+++ b/packages/utils/src/constants/misc.ts
@@ -28,7 +28,7 @@ export const GOOGLE_FAVICON_URL =
export const OG_AVATAR_URL = "https://api.dub.co/og/avatar/";
-export const PAGINATION_LIMIT = 100;
+export const DEFAULT_PAGINATION_LIMIT = 100;
export const TWO_WEEKS_IN_SECONDS = 60 * 60 * 24 * 14;