3
3
use super :: crate_details:: CrateDetails ;
4
4
use super :: error:: Nope ;
5
5
use super :: file:: File ;
6
+ use super :: metrics;
6
7
use super :: page:: Page ;
7
8
use super :: pool:: Pool ;
8
9
use super :: redirect_base;
@@ -215,6 +216,9 @@ pub fn rustdoc_redirector_handler(req: &mut Request) -> IronResult<Response> {
215
216
/// This includes all HTML files for an individual crate, as well as the `search-index.js`, which is
216
217
/// also crate-specific.
217
218
pub fn rustdoc_html_server_handler ( req : & mut Request ) -> IronResult < Response > {
219
+ let mut rendering_time =
220
+ metrics:: RenderingTimesRecorder :: new ( & metrics:: RUSTDOC_RENDERING_TIMES ) ;
221
+
218
222
// Get the request parameters
219
223
let router = extension ! ( req, Router ) ;
220
224
@@ -246,6 +250,8 @@ pub fn rustdoc_html_server_handler(req: &mut Request) -> IronResult<Response> {
246
250
Ok ( super :: redirect ( url) )
247
251
} ;
248
252
253
+ rendering_time. step ( "match version" ) ;
254
+
249
255
// Check the database for releases with the requested version while doing the following:
250
256
// * If both the name and the version are an exact match, return the version of the crate.
251
257
// * If there is an exact match, but the requested crate name was corrected (dashes vs. underscores), redirect to the corrected name.
@@ -275,6 +281,8 @@ pub fn rustdoc_html_server_handler(req: &mut Request) -> IronResult<Response> {
275
281
return Err ( IronError :: new ( Nope :: ResourceNotFound , status:: NotFound ) ) ;
276
282
} ;
277
283
284
+ rendering_time. step ( "crate details" ) ;
285
+
278
286
// Get the crate's details from the database
279
287
let crate_details = cexpect ! ( CrateDetails :: new( & conn, & name, & version) ) ;
280
288
@@ -284,6 +292,8 @@ pub fn rustdoc_html_server_handler(req: &mut Request) -> IronResult<Response> {
284
292
return redirect ( & name, & version, & req_path[ 1 ..] ) ;
285
293
}
286
294
295
+ rendering_time. step ( "fetch from storage" ) ;
296
+
287
297
// Add rustdoc prefix, name and version to the path for accessing the file stored in the database
288
298
req_path. insert ( 0 , "rustdoc" ) ;
289
299
req_path. insert ( 1 , & name) ;
@@ -311,9 +321,12 @@ pub fn rustdoc_html_server_handler(req: &mut Request) -> IronResult<Response> {
311
321
312
322
// Serve non-html files directly
313
323
if !path. ends_with ( ".html" ) {
324
+ rendering_time. step ( "serve asset" ) ;
314
325
return Ok ( file. serve ( ) ) ;
315
326
}
316
327
328
+ rendering_time. step ( "parse html" ) ;
329
+
317
330
let file_content = ctry ! ( String :: from_utf8( file. 0 . content) ) ;
318
331
// Extract the head and body of the rustdoc file so that we can insert it into our own html
319
332
let ( head, body, mut body_class) = ctry ! ( utils:: extract_head_and_body( & file_content) ) ;
@@ -326,6 +339,8 @@ pub fn rustdoc_html_server_handler(req: &mut Request) -> IronResult<Response> {
326
339
body_class. push_str ( " container-rustdoc" ) ;
327
340
}
328
341
342
+ rendering_time. step ( "serve html" ) ;
343
+
329
344
let latest_release = crate_details. latest_release ( ) ;
330
345
331
346
// Get the latest version of the crate
0 commit comments