perf(user): 关注结算异步化并去除冗余勋章评估

This commit is contained in:
kate522 committed 2026-08-23 15:44:56 +08:00
1 parent 2c1f08deb1
commit 42288bb0b1
4 files changed
+39 -34

No files matched your search

+15 -1
View File
@@ -47,10 +47,24 @@ class Follow {
if ($result === false) {
return false;
}
do_action('aksrt_user_followed', $follower_id, $following_id);
self::defer_action('aksrt_user_followed', $follower_id, $following_id);
return true;
}
/**
* 在响应送达客户端之后再触发结算钩子(积分/勋章/等级),
* 避免重度订阅者阻塞关注接口。非 PHP-FPM 环境退化为
* shutdown 时机同步执行,行为与直接 do_action 等价。
*/
private static function defer_action(string $hook, int ...$args): void {
register_shutdown_function(static function () use ($hook, $args): void {
if (function_exists('fastcgi_finish_request')) {
fastcgi_finish_request();
}
do_action($hook, ...$args);
});
}
/**
* 取消关注
*/