remove(api): profile alias are no gone since not used
This commit is contained in:
@@ -4,17 +4,10 @@ import type { FastifyReply, FastifyRequest } from 'fastify';
|
|||||||
import { path, assocPath, pathOr, pick } from 'ramda';
|
import { path, assocPath, pathOr, pick } from 'ramda';
|
||||||
|
|
||||||
import { generateDeviceId, parseUserAgent } from '@openpanel/common/server';
|
import { generateDeviceId, parseUserAgent } from '@openpanel/common/server';
|
||||||
import {
|
import { getProfileById, getSalts, upsertProfile } from '@openpanel/db';
|
||||||
createProfileAlias,
|
|
||||||
getProfileById,
|
|
||||||
getProfileIdCached,
|
|
||||||
getSalts,
|
|
||||||
upsertProfile,
|
|
||||||
} from '@openpanel/db';
|
|
||||||
import { eventsQueue } from '@openpanel/queue';
|
import { eventsQueue } from '@openpanel/queue';
|
||||||
import { getRedisCache } from '@openpanel/redis';
|
import { getRedisCache } from '@openpanel/redis';
|
||||||
import type {
|
import type {
|
||||||
AliasPayload,
|
|
||||||
DecrementPayload,
|
DecrementPayload,
|
||||||
IdentifyPayload,
|
IdentifyPayload,
|
||||||
IncrementPayload,
|
IncrementPayload,
|
||||||
@@ -110,12 +103,7 @@ export async function handler(
|
|||||||
}
|
}
|
||||||
|
|
||||||
const identity = getIdentity(request.body);
|
const identity = getIdentity(request.body);
|
||||||
const profileId = identity?.profileId
|
const profileId = identity?.profileId;
|
||||||
? await getProfileIdCached({
|
|
||||||
projectId,
|
|
||||||
profileId: identity?.profileId,
|
|
||||||
})
|
|
||||||
: undefined;
|
|
||||||
|
|
||||||
// We might get a profileId from the alias table
|
// We might get a profileId from the alias table
|
||||||
// If we do, we should use that instead of the one from the payload
|
// If we do, we should use that instead of the one from the payload
|
||||||
@@ -183,9 +171,10 @@ export async function handler(
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'alias': {
|
case 'alias': {
|
||||||
await alias({
|
reply.status(400).send({
|
||||||
payload: request.body.payload,
|
status: 400,
|
||||||
projectId,
|
error: 'Bad Request',
|
||||||
|
message: 'Alias is not supported',
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -305,20 +294,6 @@ async function identify({
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function alias({
|
|
||||||
payload,
|
|
||||||
projectId,
|
|
||||||
}: {
|
|
||||||
payload: AliasPayload;
|
|
||||||
projectId: string;
|
|
||||||
}) {
|
|
||||||
await createProfileAlias({
|
|
||||||
alias: payload.alias,
|
|
||||||
profileId: payload.profileId,
|
|
||||||
projectId,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
async function increment({
|
async function increment({
|
||||||
payload,
|
payload,
|
||||||
projectId,
|
projectId,
|
||||||
|
|||||||
@@ -188,30 +188,6 @@ export function transformProfile({
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function createProfileAlias({
|
|
||||||
projectId,
|
|
||||||
alias,
|
|
||||||
profileId,
|
|
||||||
}: {
|
|
||||||
projectId: string;
|
|
||||||
alias: string;
|
|
||||||
profileId: string;
|
|
||||||
}) {
|
|
||||||
await getProfileIdCached.clear({ profileId, projectId });
|
|
||||||
await ch.insert({
|
|
||||||
table: TABLE_NAMES.alias,
|
|
||||||
format: 'JSONEachRow',
|
|
||||||
values: [
|
|
||||||
{
|
|
||||||
projectId,
|
|
||||||
profile_id: profileId,
|
|
||||||
alias,
|
|
||||||
created_at: new Date(),
|
|
||||||
},
|
|
||||||
],
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function upsertProfile(
|
export async function upsertProfile(
|
||||||
{
|
{
|
||||||
id,
|
id,
|
||||||
@@ -240,31 +216,3 @@ export async function upsertProfile(
|
|||||||
isFromEvent,
|
isFromEvent,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getProfileId({
|
|
||||||
profileId,
|
|
||||||
projectId,
|
|
||||||
}: {
|
|
||||||
profileId: number | string | undefined;
|
|
||||||
projectId: string;
|
|
||||||
}) {
|
|
||||||
if (!profileId) {
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
|
|
||||||
const res = await chQuery<{
|
|
||||||
alias: string;
|
|
||||||
profile_id: string;
|
|
||||||
project_id: string;
|
|
||||||
}>(
|
|
||||||
`SELECT * FROM ${TABLE_NAMES.alias} WHERE project_id = '${projectId}' AND (alias = '${profileId}' OR profile_id = '${profileId}')`,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (res[0]) {
|
|
||||||
return res[0].profile_id;
|
|
||||||
}
|
|
||||||
|
|
||||||
return String(profileId);
|
|
||||||
}
|
|
||||||
|
|
||||||
export const getProfileIdCached = cacheable(getProfileId, 60 * 30);
|
|
||||||
|
|||||||
Reference in New Issue
Block a user