perf(revenue): server-render the promotion link and stop settling on reads
Opening the 推广收益 tab was slow because every read path ran settlement and two COUNT aggregates before the browser could show the link. - profile-revenue.php: the link input now carries a server-rendered value from ReferralAttribution::create_link(), so 复制链接 works on first paint instead of after a REST round trip - CommissionLedger::overview() no longer calls lazy_settle_due(); the lazy-settlement hook and its static flag are gone. Settlement runs only on the existing hourly aksrt_affiliate_settle_due cron, which uses a larger batch (100 vs 20) and would otherwise re-run up to 20 locked SELECT..FOR UPDATE + write cycles inside a GET request - ReferralAttribution::rest_me() drops the lazy_settle_due() call and the stats() result; stats() itself is deleted — its two COUNTs (one of them COUNT(DISTINCT source_user_id)) had no consumer left once the 推广人数 row was removed - credits.js: reads the link from the already-rendered input and only fetches /revenue/me for poster config and commission ratio. A failed fetch no longer blocks copying — it silently skips the poster enhancement - tests: the lazy-settlement contract is inverted to assert the read path stays read-only and cron stays wired; new assertions pin the server-rendered value and the no-COUNT REST payload Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -51,6 +51,21 @@ test('revenue detail card is a four-row info list with no standalone QR block',
|
||||
assert.match(script, /data-affiliate-poster-download/)
|
||||
assert.match(script, /openModal\(modal\)/)
|
||||
assert.match(script, /link\.download = 'referral-poster\.png'/)
|
||||
// 链接由 PHP 直出:复制按钮立即可用,REST 只负责海报配置与佣金比例。
|
||||
assert.match(script, /var url = input \? input\.value : '';/)
|
||||
assert.match(script, /if \(copy\) copy\.disabled = !url;/)
|
||||
assert.doesNotMatch(script, /input\.value = j\.url/)
|
||||
})
|
||||
|
||||
test('promotion link is server-rendered so it needs no round trip', () => {
|
||||
const template = read('inc', 'helpers', 'user-center-renderers', 'profile-revenue.php')
|
||||
// input 带服务端 value,不依赖 JS 回填。
|
||||
assert.match(template, /data-affiliate-link value="<\?php echo esc_attr\(\$affiliate_link_url\); \?>"/)
|
||||
assert.match(template, /create_link\(\$user_id\)\['url'\]/)
|
||||
const attribution = read('src', 'Payment', 'ReferralAttribution.php')
|
||||
// rest_me 不再做 COUNT 聚合,也不触发结算。
|
||||
assert.doesNotMatch(attribution, /\$this->stats\(\$user_id\)/)
|
||||
assert.doesNotMatch(attribution, /lazy_settle_due\(\)/)
|
||||
})
|
||||
|
||||
test('poster canvas is built from admin-configured copy and gated on the poster switch', () => {
|
||||
@@ -67,7 +82,7 @@ test('poster canvas is built from admin-configured copy and gated on the poster
|
||||
|
||||
const script = read('assets', 'js', 'credits.js')
|
||||
// 海报仅在开关开启时暴露按钮;绘制含顶部图、文案换行、二维码与站点名。
|
||||
assert.match(script, /initAffiliatePoster\(root, j\.url \|\| '', j\.poster \|\| \{\}, j\.site_name \|\| document\.title\)/)
|
||||
assert.match(script, /initAffiliatePoster\(root, url \|\| j\.url \|\| '', j\.poster \|\| \{\}, j\.site_name \|\| document\.title\)/)
|
||||
assert.match(script, /poster\.enabled !== true\) return/)
|
||||
assert.match(script, /function buildPosterCanvas/)
|
||||
assert.match(script, /function wrapText\(ctx, text, maxWidth\)/)
|
||||
|
||||
Reference in New Issue
Block a user