fix(growth): 修复游客资料承接与活动时区
- 资料承接:填补新账号缺失字段,保留已有称呼和显式空身份 - 站内活动:按北京时间比较日程,避免数据库时区造成八小时偏移 - 回归:补充薄资料账号及真实UTC数据库活动窗口验证
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
/** 站内生命周期运营:服务端分群、稳定对照组、每日频控与独立曝光/点击回执。 */
|
||||
/** 站内生命周期运营:日程按北京时间比较,不依赖MySQL会话时区;频控沿用数据库自然日。 */
|
||||
import { randomUUID } from "node:crypto";
|
||||
import { rows, write, transaction } from "../digital.repository";
|
||||
import { bucket } from "./growth.policy";
|
||||
@@ -11,7 +11,7 @@ export async function lifecycle(account: string) {
|
||||
inactive: number | null;
|
||||
replies: number;
|
||||
}>(
|
||||
"SELECT TIMESTAMPDIFF(DAY,?,NOW(3)) age,(SELECT TIMESTAMPDIFF(DAY,MAX(created_at),NOW(3)) FROM dh_growth_events WHERE account=? AND event='page_view') inactive,(SELECT COUNT(*) FROM dh_growth_requests WHERE account=? AND state='consumed') replies",
|
||||
"SELECT TIMESTAMPDIFF(DAY,?,NOW(3)) age,(SELECT TIMESTAMPDIFF(DAY,MAX(created_at),NOW(3)) FROM dh_growth_events WHERE account=? AND event IN ('page_view','chat_requested')) inactive,(SELECT COUNT(*) FROM dh_growth_requests WHERE account=? AND state='consumed' AND outcome='complete' AND purpose<>'suggestion') replies",
|
||||
[user.created_at, account, account],
|
||||
);
|
||||
return activity.age <= 7 && Number(activity.replies) < 3
|
||||
@@ -44,7 +44,7 @@ export async function campaignInbox(account: string) {
|
||||
revision: number;
|
||||
holdout_percent: number;
|
||||
}>(
|
||||
"SELECT id,revision,holdout_percent FROM dh_growth_campaigns WHERE enabled=TRUE AND segment=? AND starts_at<=NOW(3) AND ends_at>NOW(3) AND NOT EXISTS(SELECT 1 FROM dh_growth_deliveries d WHERE d.campaign_id=dh_growth_campaigns.id AND d.account=? AND d.campaign_revision=dh_growth_campaigns.revision) ORDER BY starts_at DESC LIMIT 1",
|
||||
"SELECT id,revision,holdout_percent FROM dh_growth_campaigns WHERE enabled=TRUE AND segment=? AND starts_at<=DATE_ADD(UTC_TIMESTAMP(3),INTERVAL 8 HOUR) AND ends_at>DATE_ADD(UTC_TIMESTAMP(3),INTERVAL 8 HOUR) AND NOT EXISTS(SELECT 1 FROM dh_growth_deliveries d WHERE d.campaign_id=dh_growth_campaigns.id AND d.account=? AND d.campaign_revision=dh_growth_campaigns.revision) ORDER BY starts_at DESC LIMIT 1",
|
||||
[segment, account],
|
||||
c,
|
||||
);
|
||||
@@ -63,7 +63,7 @@ export async function campaignInbox(account: string) {
|
||||
);
|
||||
});
|
||||
return rows<{ id: string; title: string; content: string }>(
|
||||
"SELECT d.id,c.title,c.content FROM dh_growth_deliveries d JOIN dh_growth_campaigns c ON c.id=d.campaign_id AND c.revision=d.campaign_revision WHERE d.account=? AND d.held_out=FALSE AND c.enabled=TRUE AND c.starts_at<=NOW(3) AND c.ends_at>NOW(3) AND d.created_at>DATE_SUB(NOW(3),INTERVAL 1 DAY) ORDER BY d.created_at DESC LIMIT 1",
|
||||
"SELECT d.id,c.title,c.content FROM dh_growth_deliveries d JOIN dh_growth_campaigns c ON c.id=d.campaign_id AND c.revision=d.campaign_revision WHERE d.account=? AND d.held_out=FALSE AND c.enabled=TRUE AND c.starts_at<=DATE_ADD(UTC_TIMESTAMP(3),INTERVAL 8 HOUR) AND c.ends_at>DATE_ADD(UTC_TIMESTAMP(3),INTERVAL 8 HOUR) AND d.created_at>DATE_SUB(NOW(3),INTERVAL 1 DAY) ORDER BY d.created_at DESC LIMIT 1",
|
||||
[account],
|
||||
);
|
||||
}
|
||||
@@ -76,7 +76,7 @@ export async function campaignAction(
|
||||
const field = action === "exposure" ? "exposed_at" : "clicked_at";
|
||||
await transaction(async (c) => {
|
||||
const r = await write(
|
||||
`UPDATE dh_growth_deliveries d JOIN dh_growth_campaigns p ON p.id=d.campaign_id AND p.revision=d.campaign_revision SET d.${field}=COALESCE(d.${field},NOW(3)) WHERE d.id=? AND d.account=? AND d.held_out=FALSE AND p.enabled=TRUE AND p.ends_at>NOW(3) AND d.created_at>DATE_SUB(NOW(3),INTERVAL 1 DAY)${action === "click" ? " AND d.exposed_at IS NOT NULL" : ""}`,
|
||||
`UPDATE dh_growth_deliveries d JOIN dh_growth_campaigns p ON p.id=d.campaign_id AND p.revision=d.campaign_revision SET d.${field}=COALESCE(d.${field},NOW(3)) WHERE d.id=? AND d.account=? AND d.held_out=FALSE AND p.enabled=TRUE AND p.ends_at>DATE_ADD(UTC_TIMESTAMP(3),INTERVAL 8 HOUR) AND d.created_at>DATE_SUB(NOW(3),INTERVAL 1 DAY)${action === "click" ? " AND d.exposed_at IS NOT NULL" : ""}`,
|
||||
[id, account],
|
||||
c,
|
||||
);
|
||||
|
||||
@@ -182,16 +182,20 @@ export async function mergeGuest(guest: string, account: string) {
|
||||
existingProfile = profiles.find((p) => p.account === account);
|
||||
if (guestProfile) {
|
||||
const sourceProfile = parseDigitalProfile(guestProfile.body),
|
||||
targetProfile = parseDigitalProfile(existingProfile?.body);
|
||||
targetProfile = parseDigitalProfile(existingProfile?.body),
|
||||
targetBody = existingProfile
|
||||
? (json<Record<string, unknown>>(existingProfile.body) ?? {})
|
||||
: {};
|
||||
// 开户时可能只有NSFW字段,记录存在不等于已经设置称呼;显式空身份也必须保留。
|
||||
await mergeDigitalProfile(
|
||||
account,
|
||||
{
|
||||
...(existingProfile
|
||||
...(typeof targetBody.persona === "string"
|
||||
? {}
|
||||
: {
|
||||
persona: sourceProfile.persona,
|
||||
userName: sourceProfile.userName,
|
||||
}),
|
||||
: { persona: sourceProfile.persona }),
|
||||
...(typeof targetBody.userName === "string"
|
||||
? {}
|
||||
: { userName: sourceProfile.userName }),
|
||||
favorites: [
|
||||
...new Set([
|
||||
...targetProfile.favorites,
|
||||
|
||||
Reference in New Issue
Block a user