After persist the live activity data for welcome4

This commit is contained in:
Your Name 2026-10-19 20:01:29 +02:00
parent 8dfb66f842
commit 4f0e0b22ef
8 changed files with 59 additions and 11 deletions

View File

@ -2794,6 +2794,7 @@ CREATE TABLE IF NOT EXISTS marketing_live_activity_settings (
cache_ttl_seconds INT NOT NULL DEFAULT 12 CHECK (cache_ttl_seconds > 0),
max_synthetic_withdrawals INT NOT NULL DEFAULT 12 CHECK (max_synthetic_withdrawals >= 0 AND max_synthetic_withdrawals <= 100),
synthetic_withdrawal_amounts INT[] NOT NULL DEFAULT ARRAY[20,35,50,80,100,120,200,250,300,450,500,800],
withdrawal_real_window_hours INT NOT NULL DEFAULT 48 CHECK (withdrawal_real_window_hours > 0 AND withdrawal_real_window_hours <= 720),
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);
@ -2831,6 +2832,15 @@ BEGIN
ADD COLUMN display_active_spread INT NOT NULL DEFAULT 40
CHECK (display_active_spread >= 0 AND display_active_spread <= 500);
END IF;
IF NOT EXISTS (
SELECT 1 FROM information_schema.columns
WHERE table_schema = 'public' AND table_name = 'marketing_live_activity_settings'
AND column_name = 'withdrawal_real_window_hours'
) THEN
ALTER TABLE marketing_live_activity_settings
ADD COLUMN withdrawal_real_window_hours INT NOT NULL DEFAULT 48
CHECK (withdrawal_real_window_hours > 0 AND withdrawal_real_window_hours <= 720);
END IF;
END $$;
INSERT INTO marketing_personas (public_id, is_active, sort_order)

View File

@ -18,6 +18,7 @@ export type MarketingLiveActivitySettingsRow = {
cache_ttl_seconds: number;
max_synthetic_withdrawals: number;
synthetic_withdrawal_amounts: number[] | string | null;
withdrawal_real_window_hours: number;
updated_at: Date;
};
@ -34,6 +35,7 @@ export type MarketingLiveActivitySettings = {
cacheTtlSeconds: number;
maxSyntheticWithdrawals: number;
syntheticWithdrawalAmounts: number[];
withdrawalRealWindowHours: number;
updatedAt: string;
};
@ -50,6 +52,7 @@ const DEFAULTS: Omit<MarketingLiveActivitySettings, 'updatedAt'> = {
cacheTtlSeconds: 12,
maxSyntheticWithdrawals: 12,
syntheticWithdrawalAmounts: [...DEFAULT_SYNTHETIC_WITHDRAWAL_AMOUNTS],
withdrawalRealWindowHours: 48,
};
function parseAmounts(raw: number[] | string | null | undefined): number[] {
@ -84,6 +87,8 @@ function mapRow(row: MarketingLiveActivitySettingsRow): MarketingLiveActivitySet
maxSyntheticWithdrawals: Number(row.max_synthetic_withdrawals) || 0,
syntheticWithdrawalAmounts:
amounts.length > 0 ? amounts : [...DEFAULT_SYNTHETIC_WITHDRAWAL_AMOUNTS],
withdrawalRealWindowHours:
Number(row.withdrawal_real_window_hours) || DEFAULTS.withdrawalRealWindowHours,
updatedAt: row.updated_at.toISOString(),
};
}
@ -91,7 +96,7 @@ function mapRow(row: MarketingLiveActivitySettingsRow): MarketingLiveActivitySet
const SELECT_COLS = `id, enabled, real_active_threshold, max_synthetic_entries, display_active_target,
display_active_spread, active_window_minutes, feed_real_fetch, client_refresh_seconds,
list_rotate_seconds, cache_ttl_seconds, max_synthetic_withdrawals,
synthetic_withdrawal_amounts, updated_at`;
synthetic_withdrawal_amounts, withdrawal_real_window_hours, updated_at`;
export async function getLiveActivitySettings(): Promise<MarketingLiveActivitySettings> {
const rows = await query<MarketingLiveActivitySettingsRow[]>(
@ -117,6 +122,7 @@ export type LiveActivitySettingsPatch = Partial<{
cacheTtlSeconds: number;
maxSyntheticWithdrawals: number;
syntheticWithdrawalAmounts: number[];
withdrawalRealWindowHours: number;
}>;
export async function updateLiveActivitySettings(
@ -137,6 +143,8 @@ export async function updateLiveActivitySettings(
maxSyntheticWithdrawals: patch.maxSyntheticWithdrawals ?? current.maxSyntheticWithdrawals,
syntheticWithdrawalAmounts:
patch.syntheticWithdrawalAmounts ?? current.syntheticWithdrawalAmounts,
withdrawalRealWindowHours:
patch.withdrawalRealWindowHours ?? current.withdrawalRealWindowHours,
};
if (!Array.isArray(next.syntheticWithdrawalAmounts) || next.syntheticWithdrawalAmounts.length === 0) {
@ -157,6 +165,7 @@ export async function updateLiveActivitySettings(
cache_ttl_seconds = $10,
max_synthetic_withdrawals = $11,
synthetic_withdrawal_amounts = $12::int[],
withdrawal_real_window_hours = $13,
updated_at = NOW()
WHERE id = 1
RETURNING ${SELECT_COLS}`,
@ -173,6 +182,7 @@ export async function updateLiveActivitySettings(
next.cacheTtlSeconds,
next.maxSyntheticWithdrawals,
next.syntheticWithdrawalAmounts,
next.withdrawalRealWindowHours,
]
);
if (!rows[0]) {

View File

@ -92,14 +92,21 @@ export type RealWithdrawalRow = {
created_at: Date;
};
/** Completed withdrawals only (confirmed payouts). */
export async function listRecentRealWithdrawals(limit: number): Promise<RealWithdrawalRow[]> {
/**
* Recent completed withdrawals within [windowHours] (default 48).
* Avoids stale multi-day payouts sticking forever when volume is low.
*/
export async function listRecentRealWithdrawals(
limit: number,
windowHours = 48
): Promise<RealWithdrawalRow[]> {
return query<RealWithdrawalRow[]>(
`SELECT id, user_id, amount::text AS amount, status, created_at
FROM transactions
WHERE type = 'withdrawal' AND status = 'completed'
AND created_at >= NOW() - ($2::int * INTERVAL '1 hour')
ORDER BY created_at DESC
LIMIT $1`,
[limit]
[limit, windowHours]
);
}

View File

@ -268,7 +268,7 @@ export async function getWithdrawalFeed(): Promise<{ items: MarketingWithdrawalI
return cached('withdrawal-feed', ttlMs, async () => {
const pad = settings.maxSyntheticWithdrawals;
const [rows, realActive, personas] = await Promise.all([
marketingRepository.listRecentRealWithdrawals(8),
marketingRepository.listRecentRealWithdrawals(8, settings.withdrawalRealWindowHours),
marketingRepository.countRecentDistinctPlayers(settings.activeWindowMinutes),
loadActivePersonasCached(ttlMs, Math.max(pad, settings.maxSyntheticEntries)),
]);

View File

@ -250,6 +250,7 @@ export const marketingLiveActivitySettingsBodySchema = atLeastOneField(
.min(1)
.max(50)
.optional(),
withdrawalRealWindowHours: z.number().int().positive().max(720).optional(),
})
);

View File

@ -42,6 +42,7 @@ type LiveActivitySettings = {
cacheTtlSeconds: number;
maxSyntheticWithdrawals: number;
syntheticWithdrawalAmounts: number[];
withdrawalRealWindowHours: number;
updatedAt: string;
};
@ -103,6 +104,7 @@ export function MarketingAdminPage() {
syntheticWithdrawalAmounts: settingsQuery.data.syntheticWithdrawalAmounts?.length
? settingsQuery.data.syntheticWithdrawalAmounts
: [20, 35, 50, 80, 100, 120, 200, 250, 300, 450, 500, 800],
withdrawalRealWindowHours: settingsQuery.data.withdrawalRealWindowHours ?? 48,
};
setForm(data);
setAmountsText(data.syntheticWithdrawalAmounts.join(', '));
@ -179,6 +181,7 @@ export function MarketingAdminPage() {
form.listRotateSeconds !== settingsQuery.data.listRotateSeconds ||
form.cacheTtlSeconds !== settingsQuery.data.cacheTtlSeconds ||
form.maxSyntheticWithdrawals !== settingsQuery.data.maxSyntheticWithdrawals ||
form.withdrawalRealWindowHours !== settingsQuery.data.withdrawalRealWindowHours ||
!amountsEqual(parsedAmounts, settingsQuery.data.syntheticWithdrawalAmounts));
if (settingsQuery.isLoading || !form) {
@ -314,15 +317,25 @@ export function MarketingAdminPage() {
fullWidth
/>
<TextField
label={t('admin.marketing.syntheticWithdrawalAmounts')}
value={amountsText}
onChange={(e) => setAmountsText(e.target.value)}
helperText={t('admin.marketing.syntheticWithdrawalAmountsHelper')}
label={t('admin.marketing.withdrawalRealWindowHours')}
type="number"
value={form.withdrawalRealWindowHours}
onChange={(e) =>
setForm({ ...form, withdrawalRealWindowHours: Number(e.target.value) || 0 })
}
helperText={t('admin.marketing.withdrawalRealWindowHoursHelper')}
fullWidth
multiline
minRows={2}
/>
</Stack>
<TextField
label={t('admin.marketing.syntheticWithdrawalAmounts')}
value={amountsText}
onChange={(e) => setAmountsText(e.target.value)}
helperText={t('admin.marketing.syntheticWithdrawalAmountsHelper')}
fullWidth
multiline
minRows={2}
/>
{saveMut.isError && (
<Alert severity="error">
@ -353,6 +366,7 @@ export function MarketingAdminPage() {
cacheTtlSeconds: form.cacheTtlSeconds,
maxSyntheticWithdrawals: form.maxSyntheticWithdrawals,
syntheticWithdrawalAmounts: parsedAmounts,
withdrawalRealWindowHours: form.withdrawalRealWindowHours,
});
}}
>

View File

@ -2187,6 +2187,9 @@ export const en = {
maxSyntheticWithdrawals: 'Max synthetic withdrawals',
maxSyntheticWithdrawalsHelper:
'Cap of fictive rows added to the withdrawals feed (0–100). Same enable/threshold as Live Activity.',
withdrawalRealWindowHours: 'Real withdrawals window (hours)',
withdrawalRealWindowHoursHelper:
'Only show real completed payouts newer than this (default 48). Older ones drop out so the feed can rotate with synthetics.',
syntheticWithdrawalAmounts: 'Withdrawal amounts',
syntheticWithdrawalAmountsHelper:
'Comma-separated display amounts (e.g. 20, 35, 50, 100). Rotated across active personas.',

View File

@ -2207,6 +2207,9 @@ export const fr = {
maxSyntheticWithdrawals: 'Max retraits synthétiques',
maxSyntheticWithdrawalsHelper:
'Plafond de lignes fictives ajoutées au feed retraits (0–100). Même activation/seuil que Live Activity.',
withdrawalRealWindowHours: 'Fenêtre retraits réels (heures)',
withdrawalRealWindowHoursHelper:
'N’afficher que les vrais retraits completed plus récents que cette durée (défaut 48 h). Les plus anciens sortent pour laisser tourner les fictifs.',
syntheticWithdrawalAmounts: 'Montants de retraits',
syntheticWithdrawalAmountsHelper:
'Montants affichés séparés par des virgules (ex. 20, 35, 50, 100). Rotation sur les personas actifs.',