Skip to content

🐸 Rybbit - open-source and privacy-friendly alternative to Google Analytics that is 10x more intuitive.

Refactor PreviousChart component and update monthly usage checker query

Bill Yangd3dab5ab4b3b
diff --git a/client/src/app/[site]/main/components/MainSection/PreviousChart.tsx b/client/src/app/[site]/main/components/MainSection/PreviousChart.tsx
index f40a81b90..25b936b03 100644
--- a/client/src/app/[site]/main/components/MainSection/PreviousChart.tsx
+++ b/client/src/app/[site]/main/components/MainSection/PreviousChart.tsx
@@ -9,16 +9,7 @@ import { Time } from "../../../../../components/DateSelector/types";
import { TimeBucket } from "@rybbit/shared";
const getMin = (time: Time, bucket: TimeBucket) => {
- if (time.mode === "past-minutes") {
- if (bucket === "hour") {
- return DateTime.now()
- .setZone("UTC")
- .minus({ minutes: time.pastMinutesStart * 2 })
- .startOf("hour")
- .toJSDate();
- }
- undefined;
- } else if (time.mode === "day") {
+ if (time.mode === "day") {
const dayDate = DateTime.fromISO(time.day).startOf("day");
return dayDate.toJSDate();
} else if (time.mode === "week") {
@@ -31,6 +22,16 @@ const getMin = (time: Time, bucket: TimeBucket) => {
const yearDate = DateTime.fromISO(time.year).startOf("year");
return yearDate.toJSDate();
}
+ // else if (time.mode === "past-minutes") {
+ // if (bucket === "hour") {
+ // return DateTime.now()
+ // .setZone("UTC")
+ // .minus({ minutes: time.pastMinutesStart * 2 })
+ // .startOf("hour")
+ // .toJSDate();
+ // }
+ // undefined;
+ // }
return undefined;
};
@@ -80,7 +81,7 @@ export function PreviousChart({
precision: "second",
useUTC: true,
min,
- max: maxPastMinutes,
+ // max: maxPastMinutes,
}}
yScale={{
type: "linear",
diff --git a/server/src/cron/monthly-usage-checker.ts b/server/src/cron/monthly-usage-checker.ts
index 2b72d149e..28af0a253 100644
--- a/server/src/cron/monthly-usage-checker.ts
+++ b/server/src/cron/monthly-usage-checker.ts
@@ -160,7 +160,7 @@ async function getMonthlyPageviews(
query: `
SELECT COUNT(*) as count
FROM events
- WHERE site_id IN (${siteIds.join(",")})
+ WHERE site_id IN (${siteIds.join(",")}) AND type = 'pageview'
AND timestamp >= toDate('${periodStart}')
`,
format: "JSONEachRow",