fix: minor things before merging new order keys
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import type { FastifyReply, FastifyRequest } from 'fastify';
|
import type { FastifyReply, FastifyRequest } from 'fastify';
|
||||||
import { assocPath, pathOr, pick } from 'ramda';
|
import { assocPath, pathOr, pick } from 'ramda';
|
||||||
|
|
||||||
|
import { HttpError } from '@/utils/errors';
|
||||||
import { generateId, slug } from '@openpanel/common';
|
import { generateId, slug } from '@openpanel/common';
|
||||||
import { generateDeviceId, parseUserAgent } from '@openpanel/common/server';
|
import { generateDeviceId, parseUserAgent } from '@openpanel/common/server';
|
||||||
import { getProfileById, getSalts, upsertProfile } from '@openpanel/db';
|
import { getProfileById, getSalts, upsertProfile } from '@openpanel/db';
|
||||||
@@ -187,9 +188,16 @@ export async function handler(
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'identify': {
|
case 'identify': {
|
||||||
|
const payload = request.body.payload;
|
||||||
const geo = await getGeoLocation(ip);
|
const geo = await getGeoLocation(ip);
|
||||||
|
if (!payload.profileId) {
|
||||||
|
throw new HttpError('Missing profileId', {
|
||||||
|
status: 400,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
await identify({
|
await identify({
|
||||||
payload: request.body.payload,
|
payload,
|
||||||
projectId,
|
projectId,
|
||||||
geo,
|
geo,
|
||||||
ua,
|
ua,
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
import { TABLE_NAMES, chQuery } from '@openpanel/db';
|
import { TABLE_NAMES, chQuery } from '@openpanel/db';
|
||||||
|
|
||||||
export async function ping() {
|
export async function ping() {
|
||||||
|
if (process.env.DISABLE_PING) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const [res] = await chQuery<{ count: number }>(
|
const [res] = await chQuery<{ count: number }>(
|
||||||
`SELECT COUNT(*) as count FROM ${TABLE_NAMES.events}`,
|
`SELECT COUNT(*) as count FROM ${TABLE_NAMES.events}`,
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -9,25 +9,6 @@ import {
|
|||||||
} from '../src/clickhouse/migration';
|
} from '../src/clickhouse/migration';
|
||||||
import { getIsCluster } from './helpers';
|
import { getIsCluster } from './helpers';
|
||||||
|
|
||||||
/**
|
|
||||||
* Migration to update ORDER BY keys for events and sessions tables.
|
|
||||||
*
|
|
||||||
* Changes:
|
|
||||||
* - Events: Remove profile_id from ORDER BY, add created_at for better ordering
|
|
||||||
* Old: ['project_id', 'toDate(created_at)', 'profile_id', 'name']
|
|
||||||
* New: ['project_id', 'toDate(created_at)', 'created_at', 'name']
|
|
||||||
*
|
|
||||||
* - Sessions: Remove profile_id from ORDER BY, reorder to match query patterns
|
|
||||||
* Old: ['project_id', 'id', 'toDate(created_at)', 'profile_id']
|
|
||||||
* New: ['project_id', 'toDate(created_at)', 'created_at', 'id']
|
|
||||||
*
|
|
||||||
* Rationale:
|
|
||||||
* - project_id: Always filtered first (100% of queries)
|
|
||||||
* - toDate(created_at): Almost always filtered (95%+ of queries), good for partitioning
|
|
||||||
* - created_at: Helps with ordering within same day, matches ORDER BY patterns in queries
|
|
||||||
* - name (events): Frequently filtered (screen_view, session_start, etc.), good selectivity
|
|
||||||
* - id (sessions): Used for ordering and uniqueness in session queries
|
|
||||||
*/
|
|
||||||
export async function up() {
|
export async function up() {
|
||||||
const isClustered = getIsCluster();
|
const isClustered = getIsCluster();
|
||||||
|
|
||||||
|
|||||||
@@ -30,3 +30,7 @@ export function getIsSelfHosting() {
|
|||||||
export function getIsDry() {
|
export function getIsDry() {
|
||||||
return process.argv.includes('--dry');
|
return process.argv.includes('--dry');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getShouldIgnoreRecord() {
|
||||||
|
return process.argv.includes('--no-record');
|
||||||
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import {
|
|||||||
getIsCluster,
|
getIsCluster,
|
||||||
getIsDry,
|
getIsDry,
|
||||||
getIsSelfHosting,
|
getIsSelfHosting,
|
||||||
|
getShouldIgnoreRecord,
|
||||||
printBoxMessage,
|
printBoxMessage,
|
||||||
} from './helpers';
|
} from './helpers';
|
||||||
|
|
||||||
@@ -55,8 +56,8 @@ async function migrate() {
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
if (!getIsSelfHosting()) {
|
if (!getIsSelfHosting()) {
|
||||||
printBoxMessage('🕒 Migrations starts in 10 seconds', []);
|
|
||||||
if (!getIsDry()) {
|
if (!getIsDry()) {
|
||||||
|
printBoxMessage('🕒 Migrations starts in 10 seconds', []);
|
||||||
await new Promise((resolve) => setTimeout(resolve, 10000));
|
await new Promise((resolve) => setTimeout(resolve, 10000));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -83,7 +84,7 @@ async function runMigration(migrationsDir: string, file: string) {
|
|||||||
try {
|
try {
|
||||||
const migration = await import(path.join(migrationsDir, file));
|
const migration = await import(path.join(migrationsDir, file));
|
||||||
await migration.up();
|
await migration.up();
|
||||||
if (!getIsDry()) {
|
if (!getIsDry() && !getShouldIgnoreRecord()) {
|
||||||
await db.codeMigration.upsert({
|
await db.codeMigration.upsert({
|
||||||
where: {
|
where: {
|
||||||
name: file,
|
name: file,
|
||||||
|
|||||||
@@ -318,18 +318,13 @@ export function moveDataBetweenTables({
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// For monthly/weekly intervals with transform, we need to use the start of the next period for the upper bound
|
// For monthly/weekly intervals with transform, upperBoundDate should be currentDate
|
||||||
|
// because currentDate already represents the start of the period we're processing
|
||||||
|
// The WHERE clause uses > previousDate AND <= currentDate to get exactly one period
|
||||||
let upperBoundDate = currentDate;
|
let upperBoundDate = currentDate;
|
||||||
if (interval === 'month' && batch.transform) {
|
// Don't exceed the endDate
|
||||||
const nextMonth = new Date(currentDate);
|
if (upperBoundDate > endDate) {
|
||||||
nextMonth.setMonth(nextMonth.getMonth() + 1);
|
upperBoundDate = endDate;
|
||||||
nextMonth.setDate(1);
|
|
||||||
upperBoundDate = nextMonth;
|
|
||||||
} else if (interval === 'week' && batch.transform) {
|
|
||||||
const nextWeek = new Date(currentDate);
|
|
||||||
nextWeek.setDate(nextWeek.getDate() + 7);
|
|
||||||
const nextWeekStart = getWeekStart(nextWeek);
|
|
||||||
upperBoundDate = nextWeekStart;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const sql = `INSERT INTO ${to}
|
const sql = `INSERT INTO ${to}
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
version: '3'
|
version: "3"
|
||||||
|
|
||||||
services:
|
services:
|
||||||
op-proxy:
|
op-proxy:
|
||||||
image: caddy:2-alpine
|
image: caddy:2-alpine
|
||||||
restart: always
|
restart: always
|
||||||
ports:
|
ports:
|
||||||
- '80:80'
|
- "80:80"
|
||||||
- '443:443'
|
- "443:443"
|
||||||
volumes:
|
volumes:
|
||||||
- op-proxy-data:/data
|
- op-proxy-data:/data
|
||||||
- op-proxy-config:/config
|
- op-proxy-config:/config
|
||||||
@@ -28,7 +28,7 @@ services:
|
|||||||
volumes:
|
volumes:
|
||||||
- op-db-data:/var/lib/postgresql/data
|
- op-db-data:/var/lib/postgresql/data
|
||||||
healthcheck:
|
healthcheck:
|
||||||
test: [ 'CMD-SHELL', 'pg_isready -U postgres' ]
|
test: ["CMD-SHELL", "pg_isready -U postgres"]
|
||||||
interval: 10s
|
interval: 10s
|
||||||
timeout: 5s
|
timeout: 5s
|
||||||
retries: 5
|
retries: 5
|
||||||
@@ -49,9 +49,9 @@ services:
|
|||||||
restart: always
|
restart: always
|
||||||
volumes:
|
volumes:
|
||||||
- op-kv-data:/data
|
- op-kv-data:/data
|
||||||
command: [ 'redis-server', '--maxmemory-policy', 'noeviction' ]
|
command: ["redis-server", "--maxmemory-policy", "noeviction"]
|
||||||
healthcheck:
|
healthcheck:
|
||||||
test: [ 'CMD-SHELL', 'redis-cli ping' ]
|
test: ["CMD-SHELL", "redis-cli ping"]
|
||||||
interval: 10s
|
interval: 10s
|
||||||
timeout: 5s
|
timeout: 5s
|
||||||
retries: 5
|
retries: 5
|
||||||
@@ -65,7 +65,7 @@ services:
|
|||||||
# - 6379:6379
|
# - 6379:6379
|
||||||
|
|
||||||
op-ch:
|
op-ch:
|
||||||
image: clickhouse/clickhouse-server:24.3.2-alpine
|
image: clickhouse/clickhouse-server:25.10.2.65
|
||||||
restart: always
|
restart: always
|
||||||
volumes:
|
volumes:
|
||||||
- op-ch-data:/var/lib/clickhouse
|
- op-ch-data:/var/lib/clickhouse
|
||||||
@@ -74,7 +74,7 @@ services:
|
|||||||
- ./clickhouse/clickhouse-user-config.xml:/etc/clickhouse-server/users.d/op-user-config.xml:ro
|
- ./clickhouse/clickhouse-user-config.xml:/etc/clickhouse-server/users.d/op-user-config.xml:ro
|
||||||
- ./clickhouse/init-db.sh:/docker-entrypoint-initdb.d/init-db.sh:ro
|
- ./clickhouse/init-db.sh:/docker-entrypoint-initdb.d/init-db.sh:ro
|
||||||
healthcheck:
|
healthcheck:
|
||||||
test: [ 'CMD-SHELL', 'clickhouse-client --query "SELECT 1"' ]
|
test: ["CMD-SHELL", 'clickhouse-client --query "SELECT 1"']
|
||||||
interval: 10s
|
interval: 10s
|
||||||
timeout: 5s
|
timeout: 5s
|
||||||
retries: 5
|
retries: 5
|
||||||
@@ -89,7 +89,7 @@ services:
|
|||||||
max-file: "3"
|
max-file: "3"
|
||||||
|
|
||||||
op-api:
|
op-api:
|
||||||
image: lindesvard/openpanel-api:latest
|
image: lindesvard/openpanel-api:2.0.0
|
||||||
restart: always
|
restart: always
|
||||||
command: >
|
command: >
|
||||||
sh -c "
|
sh -c "
|
||||||
@@ -99,7 +99,7 @@ services:
|
|||||||
pnpm start
|
pnpm start
|
||||||
"
|
"
|
||||||
healthcheck:
|
healthcheck:
|
||||||
test: [ 'CMD-SHELL', 'curl -f http://localhost:3000/healthcheck || exit 1' ]
|
test: ["CMD-SHELL", "curl -f http://localhost:3000/healthcheck || exit 1"]
|
||||||
interval: 10s
|
interval: 10s
|
||||||
timeout: 5s
|
timeout: 5s
|
||||||
retries: 5
|
retries: 5
|
||||||
@@ -119,7 +119,7 @@ services:
|
|||||||
max-file: "3"
|
max-file: "3"
|
||||||
|
|
||||||
op-dashboard:
|
op-dashboard:
|
||||||
image: lindesvard/openpanel-dashboard:latest
|
image: lindesvard/openpanel-dashboard:2.0.0
|
||||||
restart: always
|
restart: always
|
||||||
depends_on:
|
depends_on:
|
||||||
op-api:
|
op-api:
|
||||||
@@ -127,7 +127,8 @@ services:
|
|||||||
env_file:
|
env_file:
|
||||||
- .env
|
- .env
|
||||||
healthcheck:
|
healthcheck:
|
||||||
test: [ 'CMD-SHELL', 'curl -f http://localhost:3000/api/healthcheck || exit 1' ]
|
test:
|
||||||
|
["CMD-SHELL", "curl -f http://localhost:3000/api/healthcheck || exit 1"]
|
||||||
interval: 10s
|
interval: 10s
|
||||||
timeout: 5s
|
timeout: 5s
|
||||||
retries: 5
|
retries: 5
|
||||||
@@ -138,7 +139,7 @@ services:
|
|||||||
max-file: "3"
|
max-file: "3"
|
||||||
|
|
||||||
op-worker:
|
op-worker:
|
||||||
image: lindesvard/openpanel-worker:latest
|
image: lindesvard/openpanel-worker:2.0.0
|
||||||
restart: always
|
restart: always
|
||||||
depends_on:
|
depends_on:
|
||||||
op-api:
|
op-api:
|
||||||
@@ -146,7 +147,7 @@ services:
|
|||||||
env_file:
|
env_file:
|
||||||
- .env
|
- .env
|
||||||
healthcheck:
|
healthcheck:
|
||||||
test: [ 'CMD-SHELL', 'curl -f http://localhost:3000/healthcheck || exit 1' ]
|
test: ["CMD-SHELL", "curl -f http://localhost:3000/healthcheck || exit 1"]
|
||||||
interval: 10s
|
interval: 10s
|
||||||
timeout: 5s
|
timeout: 5s
|
||||||
retries: 5
|
retries: 5
|
||||||
|
|||||||
Reference in New Issue
Block a user