From 3f04ae4163c34b05ce0e3da5b3ea01efa5d2a056 Mon Sep 17 00:00:00 2001 From: xiaomlove Date: Sat, 27 Sep 2025 03:28:27 +0700 Subject: [PATCH] API add more log --- app/Http/Controllers/TorrentController.php | 6 ++++++ app/Repositories/TorrentRepository.php | 8 ++++++++ include/globalfunctions.php | 5 ++++- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/TorrentController.php b/app/Http/Controllers/TorrentController.php index c8a3643a..7c9c2cd5 100644 --- a/app/Http/Controllers/TorrentController.php +++ b/app/Http/Controllers/TorrentController.php @@ -28,8 +28,11 @@ class TorrentController extends Controller public function index(Request $request, string $section = null) { + do_log("controller torrent index entry"); $result = $this->repository->getList($request, Auth::user(), $section); + do_log("controller torrent index getList"); $resource = TorrentResource::collection($result); + do_log("controller torrent index prepare resource"); return $this->success($resource); } @@ -55,11 +58,13 @@ class TorrentController extends Controller */ public function show($id) { + do_log("controller torrent show entry"); /** * @var User */ $user = Auth::user(); $torrent = $this->repository->getDetail($id, $user); + do_log("controller torrent show getDetail"); $resource = new TorrentResource($torrent); $additional = []; if ($this->hasExtraField('bonus_reward_values')) { @@ -68,6 +73,7 @@ class TorrentController extends Controller $extraSettingsNames = ['torrent.claim_torrent_user_counts_up_limit']; $this->appendExtraSettings($additional, $extraSettingsNames); $resource->additional($additional); + do_log("controller torrent show prepare resource"); return $this->success($resource); } diff --git a/app/Repositories/TorrentRepository.php b/app/Repositories/TorrentRepository.php index 1f310a79..7c6abc79 100644 --- a/app/Repositories/TorrentRepository.php +++ b/app/Repositories/TorrentRepository.php @@ -152,7 +152,9 @@ class TorrentRepository extends BaseRepository if (!$apiQueryBuilder->hasSort() || !$apiQueryBuilder->hasSort('id')) { $query->orderBy("id", "DESC"); } + do_log("before query torrent list"); $torrents = $query->paginate($this->getPerPageFromRequest($request)); + do_log("after query torrent list"); return $this->appendIncludeFields($apiQueryBuilder, $user, $torrents); } @@ -175,7 +177,9 @@ class TorrentRepository extends BaseRepository ->allowIncludeCounts($allowIncludeCounts) ->allowIncludeFields($allowIncludeFields) ; + do_log("before query torrent detail"); $torrent = $apiQueryBuilder->build()->findOrFail($id); + do_log("before query torrent detail"); $torrentList = $this->appendIncludeFields($apiQueryBuilder, $user, [$torrent]); return $torrentList[0]; } @@ -199,6 +203,7 @@ class TorrentRepository extends BaseRepository if ($hasFieldHasRewarded = $apiQueryBuilder->hasIncludeField('has_rewarded')) { $rewardData = $user->reward_torrent_logs()->whereIn('torrentid', $torrentIdArr)->get()->keyBy('torrentid'); } + do_log("after prepare has data"); foreach ($torrentList as $torrent) { $id = $torrent->id; @@ -216,7 +221,9 @@ class TorrentRepository extends BaseRepository } if ($apiQueryBuilder->hasIncludeField('description') && $apiQueryBuilder->hasInclude('extra')) { + do_log("before format_description of torrent: {$torrent->id}"); $descriptionArr = format_description($torrent->extra->descr ?? ''); + do_log("after format_description of torrent: {$torrent->id}"); $torrent->description = $descriptionArr; $torrent->images = get_image_from_description($descriptionArr); } @@ -224,6 +231,7 @@ class TorrentRepository extends BaseRepository $torrent->download_url = $this->getDownloadUrl($id, $user); } } + do_log("after fill has data"); return $torrentList; } diff --git a/include/globalfunctions.php b/include/globalfunctions.php index d3e97b80..2684393e 100644 --- a/include/globalfunctions.php +++ b/include/globalfunctions.php @@ -542,6 +542,7 @@ function nexus_json_encode($data) function api(...$args) { + do_log("api begin"); if (func_num_args() < 3) { //参数少于3个时,默认为错误状态。 $ret = -1; @@ -555,6 +556,7 @@ function api(...$args) if ($data instanceof \Illuminate\Http\Resources\Json\JsonResource) { $data = $data->response()->getData(true); } + do_log("api after prepare data"); // dd($data); $time = (float)number_format(microtime(true) - nexus()->getStartTimestamp(), 3); $count = null; @@ -583,7 +585,7 @@ function api(...$args) $results['recordsTotal'] = $count; $results['recordsFiltered'] = $count; } - + do_log("api end"); return $results; } @@ -599,6 +601,7 @@ function success(...$args) $msg = $args[0]; $data = $args[1]; } + do_log("success before api"); return api($ret, $msg, $data); }