Skip to content

Commit

Permalink
Merge pull request umami-software#2362 from umami-software/dev
Browse files Browse the repository at this point in the history
Hotfix
  • Loading branch information
mikecao authored Oct 20, 2023
2 parents b9477db + 0901a00 commit 91b6dc5
Show file tree
Hide file tree
Showing 8 changed files with 2,141 additions and 2,240 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ ENV NEXT_TELEMETRY_DISABLED 1
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs

RUN yarn add npm-run-all dotenv prisma
RUN yarn add npm-run-all dotenv prisma semver

# You only need to copy next.config.js if you are NOT using the default configuration
COPY --from=builder /app/next.config.js .
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"@react-spring/web": "^9.7.3",
"@tanstack/react-query": "^4.33.0",
"@umami/prisma-client": "^0.3.0",
"@umami/redis-client": "^0.15.0",
"@umami/redis-client": "^0.16.0",
"chalk": "^4.1.1",
"chart.js": "^4.2.1",
"chartjs-adapter-date-fns": "^3.0.0",
Expand All @@ -93,9 +93,10 @@
"maxmind": "^4.3.6",
"moment-timezone": "^0.5.35",
"next": "13.5.3",
"next-basics": "^0.36.0",
"next-basics": "^0.37.0",
"node-fetch": "^3.2.8",
"npm-run-all": "^4.1.5",
"prisma": "5.3.1",
"react": "^18.2.0",
"react-basics": "^0.105.0",
"react-beautiful-dnd": "^13.1.0",
Expand All @@ -106,7 +107,7 @@
"react-use-measure": "^2.0.4",
"react-window": "^1.8.6",
"request-ip": "^3.3.0",
"semver": "^7.5.2",
"semver": "^7.5.4",
"thenby": "^1.3.4",
"timezone-support": "^2.0.2",
"uuid": "^9.0.0",
Expand Down Expand Up @@ -146,7 +147,6 @@
"postcss-preset-env": "7.8.3",
"postcss-rtlcss": "^4.0.1",
"prettier": "^2.6.2",
"prisma": "5.3.1",
"prompts": "2.4.2",
"rollup": "^3.28.0",
"rollup-plugin-copy": "^3.4.0",
Expand Down
15 changes: 5 additions & 10 deletions src/app/(main)/console/TestConsole.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,15 @@ import WebsiteChart from '../../(main)/websites/[id]/WebsiteChart';
import useApi from 'components/hooks/useApi';
import Head from 'next/head';
import Link from 'next/link';
import { useRouter } from 'next/navigation';
import useNavigation from 'components/hooks/useNavigation';
import Script from 'next/script';
import { Button } from 'react-basics';
import styles from './TestConsole.module.css';

export function TestConsole() {
export function TestConsole({ websiteId }) {
const { get, useQuery } = useApi();
const { data, isLoading, error } = useQuery(['websites:me'], () => get('/me/websites'));
const router = useRouter();
const {
basePath,
query: { id },
} = router;
const { router } = useNavigation();

function handleChange(value) {
router.push(`/console/${value}`);
Expand Down Expand Up @@ -72,7 +68,6 @@ export function TestConsole() {
return null;
}

const [websiteId] = id || [];
const website = data?.data.find(({ id }) => websiteId === id);

return (
Expand All @@ -87,8 +82,8 @@ export function TestConsole() {
<>
<Script
async
data-website-id={website.id}
src={`${basePath}/script.js`}
data-website-id={websiteId}
src={`${process.env.basePath}/script.js`}
data-cache="true"
/>
<div className={styles.test}>
Expand Down
4 changes: 2 additions & 2 deletions src/app/(main)/console/[[...id]]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ async function getEnabled() {
return !!process.env.ENABLE_TEST_CONSOLE;
}

export default async function ConsolePage() {
export default async function ({ params: { id } }) {
const enabled = await getEnabled();

if (!enabled) {
return null;
}

return <TestConsole />;
return <TestConsole websiteId={id?.[0]} />;
}

export const metadata: Metadata = {
Expand Down
18 changes: 9 additions & 9 deletions src/lib/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,57 +3,57 @@ import redis from '@umami/redis-client';
import { getSession, getUserById, getWebsiteById } from '../queries';

async function fetchWebsite(id): Promise<Website> {
return redis.fetchObject(`website:${id}`, () => getWebsiteById(id), 86400);
return redis.getCache(`website:${id}`, () => getWebsiteById(id), 86400);
}

async function storeWebsite(data) {
const { id } = data;
const key = `website:${id}`;

const obj = await redis.storeObject(key, data);
const obj = await redis.setCache(key, data);
await redis.expire(key, 86400);

return obj;
}

async function deleteWebsite(id) {
return redis.deleteObject(`website:${id}`);
return redis.deleteCache(`website:${id}`);
}

async function fetchUser(id): Promise<User> {
return redis.fetchObject(`user:${id}`, () => getUserById(id, { includePassword: true }), 86400);
return redis.getCache(`user:${id}`, () => getUserById(id, { includePassword: true }), 86400);
}

async function storeUser(data) {
const { id } = data;
const key = `user:${id}`;

const obj = await redis.storeObject(key, data);
const obj = await redis.setCache(key, data);
await redis.expire(key, 86400);

return obj;
}

async function deleteUser(id) {
return redis.deleteObject(`user:${id}`);
return redis.deleteCache(`user:${id}`);
}

async function fetchSession(id) {
return redis.fetchObject(`session:${id}`, () => getSession(id), 86400);
return redis.getCache(`session:${id}`, () => getSession(id), 86400);
}

async function storeSession(data) {
const { id } = data;
const key = `session:${id}`;

const obj = await redis.storeObject(key, data);
const obj = await redis.setCache(key, data);
await redis.expire(key, 86400);

return obj;
}

async function deleteSession(id) {
return redis.deleteObject(`session:${id}`);
return redis.deleteCache(`session:${id}`);
}

async function fetchUserBlock(userId: string) {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/crypto.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export function salt() {
export function uuid(...args) {
if (!args.length) return v4();

return v5(hash(...args), v5.DNS);
return v5(hash(...args, salt()), v5.DNS);
}

export function isUuid(value) {
Expand Down
12 changes: 10 additions & 2 deletions src/queries/analytics/eventData/getEventDataUsage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ export function getEventDataUsage(...args: [websiteIds: string[], startDate: Dat
});
}

function clickhouseQuery(websiteIds: string[], startDate: Date, endDate: Date) {
function clickhouseQuery(
websiteIds: string[],
startDate: Date,
endDate: Date,
): Promise<{ websiteId: string; count: number }[]> {
const { rawQuery } = clickhouse;

return rawQuery(
Expand All @@ -26,5 +30,9 @@ function clickhouseQuery(websiteIds: string[], startDate: Date, endDate: Date) {
startDate,
endDate,
},
);
).then(a => {
return Object.values(a).map(a => {
return { websiteId: a.websiteId, count: Number(a.count) };
});
});
}
Loading

1 comment on commit 91b6dc5

@vercel
Copy link

@vercel vercel bot commented on 91b6dc5 Oct 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.