@@ -28,7 +28,8 @@ public function handle(Request $request, EntriesRepository $repository): Respons
2828 try {
2929 if ($ id = $ request ->get ('id ' )) {
3030 $ includeRelated = $ request ->boolean ('include_related ' , true );
31- return $ this ->getRequestDetails ($ id , $ includeRelated , $ repository );
31+ $ includeQueries = $ request ->boolean ('include_queries ' , false );
32+ return $ this ->getRequestDetails ($ id , $ includeRelated , $ includeQueries , $ repository );
3233 }
3334 return $ this ->listRequests ($ request , $ repository );
3435 } catch (\Exception $ e ) {
@@ -44,7 +45,8 @@ public function schema(JsonSchema $schema): array
4445 'method ' => $ schema ->string ()->description ('Filter by HTTP method ' ),
4546 'status ' => $ schema ->integer ()->description ('Filter by status code ' ),
4647 'path ' => $ schema ->string ()->description ('Filter by path ' ),
47- 'include_related ' => $ schema ->boolean ()->default (true ),
48+ 'include_related ' => $ schema ->boolean ()->default (true )->description ('Include summary of related entries ' ),
49+ 'include_queries ' => $ schema ->boolean ()->default (false )->description ('Include detailed queries associated with this request ' ),
4850 ];
4951 }
5052
@@ -61,7 +63,11 @@ protected function listRequests(Request $request, EntriesRepository $repository)
6163 $ options ->tag ('status: ' . $ status );
6264 }
6365 if ($ path = $ request ->get ('path ' )) {
64- $ options ->tag ('path: ' . $ path );
66+ $ uuids = $ this ->getRequestUuidsByPath ($ path , $ limit );
67+ if (empty ($ uuids )) {
68+ return Response::text ("No requests found for path: {$ path }" );
69+ }
70+ $ options ->uuids ($ uuids );
6571 }
6672
6773 $ entries = $ repository ->get (EntryType::REQUEST , $ options );
@@ -110,7 +116,7 @@ protected function listRequests(Request $request, EntriesRepository $repository)
110116 return Response::text ($ table );
111117 }
112118
113- protected function getRequestDetails (string $ id , bool $ includeRelated , EntriesRepository $ repository ): Response
119+ protected function getRequestDetails (string $ id , bool $ includeRelated , bool $ includeQueries , EntriesRepository $ repository ): Response
114120 {
115121 $ entry = $ repository ->find ($ id );
116122 if (!$ entry ) {
@@ -128,27 +134,70 @@ protected function getRequestDetails(string $id, bool $includeRelated, EntriesRe
128134 $ output .= "Created At: {$ createdAt }\n" ;
129135
130136 $ relatedSummary = [];
131- if ($ includeRelated && isset ($ entry ->batchId ) && $ entry ->batchId ) {
132- $ summary = $ this ->getBatchSummary ($ entry ->batchId );
133- $ typeLabels = ['query ' => 'Queries ' , 'log ' => 'Logs ' , 'cache ' => 'Cache Operations ' ,
134- 'model ' => 'Model Events ' , 'view ' => 'Views ' , 'exception ' => 'Exceptions ' ,
135- 'event ' => 'Events ' , 'job ' => 'Jobs ' , 'mail ' => 'Mails ' ,
136- 'notification ' => 'Notifications ' , 'redis ' => 'Redis Operations ' ];
137-
138- $ output .= "\n--- Related Entries --- \n" ;
139- $ hasRelated = false ;
140- foreach ($ summary as $ type => $ count ) {
141- if ($ type !== 'request ' ) {
142- $ label = $ typeLabels [$ type ] ?? ucfirst ($ type );
143- $ output .= "- {$ label }: {$ count }\n" ;
144- $ relatedSummary [$ type ] = $ count ;
145- $ hasRelated = true ;
137+ $ batchQueries = [];
138+
139+ if (($ includeRelated || $ includeQueries ) && isset ($ entry ->batchId ) && $ entry ->batchId ) {
140+ if ($ includeRelated ) {
141+ $ summary = $ this ->getBatchSummary ($ entry ->batchId );
142+ $ typeLabels = [
143+ 'query ' => 'Queries ' ,
144+ 'log ' => 'Logs ' ,
145+ 'cache ' => 'Cache Operations ' ,
146+ 'model ' => 'Model Events ' ,
147+ 'view ' => 'Views ' ,
148+ 'exception ' => 'Exceptions ' ,
149+ 'event ' => 'Events ' ,
150+ 'job ' => 'Jobs ' ,
151+ 'mail ' => 'Mails ' ,
152+ 'notification ' => 'Notifications ' ,
153+ 'redis ' => 'Redis Operations '
154+ ];
155+
156+ $ output .= "\n--- Related Entries --- \n" ;
157+ $ hasRelated = false ;
158+ foreach ($ summary as $ type => $ count ) {
159+ if ($ type !== 'request ' ) {
160+ $ label = $ typeLabels [$ type ] ?? ucfirst ($ type );
161+ $ output .= "- {$ label }: {$ count }\n" ;
162+ $ relatedSummary [$ type ] = $ count ;
163+ $ hasRelated = true ;
164+ }
165+ }
166+ if ($ hasRelated ) {
167+ $ output .= "\nTip: Use 'queries --request_id= {$ id }' to see queries for this request. \n" ;
168+ } else {
169+ $ output .= "(No related entries found) \n" ;
146170 }
147171 }
148- if ($ hasRelated ) {
149- $ output .= "\nTip: Use 'queries --request_id= {$ id }' to see queries for this request. \n" ;
150- } else {
151- $ output .= "(No related entries found) \n" ;
172+
173+ if ($ includeQueries ) {
174+ $ queryEntries = $ this ->getEntriesByBatchId ($ entry ->batchId , 'query ' , 10 );
175+ if (!empty ($ queryEntries )) {
176+ $ output .= "\n--- Associated Queries (Top 10) --- \n" ;
177+ foreach ($ queryEntries as $ q ) {
178+ $ sql = $ q ->content ['sql ' ] ?? 'Unknown ' ;
179+ $ time = $ q ->content ['time ' ] ?? 0 ;
180+ $ location = isset ($ q ->content ['file ' ]) ? " ( {$ q ->content ['file ' ]}: {$ q ->content ['line ' ]}) " : "" ;
181+
182+ $ output .= sprintf (
183+ "[%s] %-50s (%s ms)%s \n" ,
184+ $ q ->id ,
185+ strlen ($ sql ) > 50 ? substr ($ sql , 0 , 47 ) . '... ' : $ sql ,
186+ number_format ($ time , 2 ),
187+ $ location
188+ );
189+
190+ $ batchQueries [] = [
191+ 'id ' => $ q ->id ,
192+ 'sql ' => $ sql ,
193+ 'duration ' => $ time ,
194+ 'location ' => [
195+ 'file ' => $ q ->content ['file ' ] ?? null ,
196+ 'line ' => $ q ->content ['line ' ] ?? null ,
197+ ]
198+ ];
199+ }
200+ }
152201 }
153202 }
154203
@@ -178,6 +227,10 @@ protected function getRequestDetails(string $id, bool $includeRelated, EntriesRe
178227 $ jsonData ['related_entries ' ] = $ relatedSummary ;
179228 }
180229
230+ if (!empty ($ batchQueries )) {
231+ $ jsonData ['queries ' ] = $ batchQueries ;
232+ }
233+
181234 $ output .= "\n\n--- JSON Data --- \n" . json_encode ($ jsonData , JSON_PRETTY_PRINT );
182235 return Response::text ($ output );
183236 }
0 commit comments