Skip to content

OpenPanel is an open-source web and product analytics platform, an open-source alternative to Mixpanel with optional self-hosting.

fix(api): exclude some keys for export cache

Carl-Gerhard Lindesvärdc4be1dc05d3c
diff --git a/apps/api/src/controllers/export.controller.ts b/apps/api/src/controllers/export.controller.ts
index 63cd631e5..68b3ab2fe 100644
--- a/apps/api/src/controllers/export.controller.ts
+++ b/apps/api/src/controllers/export.controller.ts
@@ -11,6 +11,7 @@ import {
} from '@openpanel/db';
import { getChart } from '@openpanel/trpc/src/routers/chart.helpers';
import { zChartInput } from '@openpanel/validation';
+import { omit } from 'ramda';
async function getProjectId(
request: FastifyRequest<{
@@ -125,7 +126,7 @@ export async function events(
const [data, totalCount] = await Promise.all([
getEventList(options),
- getEventsCountCached(options),
+ getEventsCountCached(omit(['cursor', 'take'], options)),
]);
reply.send({
diff --git a/apps/docs/src/pages/docs/sdks/export.mdx b/apps/docs/src/pages/docs/sdks/export.mdx
index 3afaec268..f8cd42047 100644
--- a/apps/docs/src/pages/docs/sdks/export.mdx
+++ b/apps/docs/src/pages/docs/sdks/export.mdx
@@ -6,14 +6,35 @@ To authenticate with the Export API, you need to use your `clientId` and `client
We expect you to send `openpanel-client-id` and `openpanel-client-secret` headers with your requests.
+Example:
+
+```bash
+curl 'https://api.openpanel.dev/export/events' \
+ -H 'openpanel-client-id: YOUR_CLIENT_ID' \
+ -H 'openpanel-client-secret: YOUR_CLIENT_SECRET'
+```
+
## Events
-Get all `screen_view` events from project `abc` between `2024-04-15` and `2024-04-18`.
+Get events from a specific project within a date range.
+
+Endpoint: `GET /export/events`
+
+Parameters:
+- project_id (required): The ID of the project
+- event (optional): Filter by event name(s). Can be a single event or an array of events.
+- start (optional): Start date (format: YYYY-MM-DD)
+- end (optional): End date (format: YYYY-MM-DD)
+- page (optional, default: 1): Page number for pagination
+- limit (optional, default: 50, max: 50): Number of events per page
+- includes (optional): Additional fields to include in the response
+
+Example:
```bash
curl 'https://api.openpanel.dev/export/events?project_id=abc&event=screen_view&start=2024-04-15&end=2024-04-18' \
- -H 'openpanel-client-id: CLIENT_ID' \
- -H 'openpanel-client-secret: CLIENT_SECRET'
+ -H 'openpanel-client-id: YOUR_CLIENT_ID' \
+ -H 'openpanel-client-secret: YOUR_CLIENT_SECRET'
```
## Profiles
diff --git a/packages/db/src/services/event.service.ts b/packages/db/src/services/event.service.ts
index e8f04c514..b1aecdcae 100644
--- a/packages/db/src/services/event.service.ts
+++ b/packages/db/src/services/event.service.ts
@@ -511,7 +511,7 @@ export async function getEventList({
});
}
-export const getEventsCountCached = cacheable(getEventsCount, 60 * 60);
+export const getEventsCountCached = cacheable(getEventsCount, 60 * 10);
export async function getEventsCount({
projectId,
profileId,