@@ -7,6 +7,7 @@ pub use self::compression::{compress, decompress, CompressionAlgorithm, Compress
7
7
use self :: database:: DatabaseBackend ;
8
8
use self :: s3:: S3Backend ;
9
9
use crate :: error:: Result ;
10
+ use crate :: web:: metrics:: RenderingTimesRecorder ;
10
11
use crate :: { db:: Pool , Config , Metrics } ;
11
12
use anyhow:: { anyhow, ensure} ;
12
13
use chrono:: { DateTime , Utc } ;
@@ -145,14 +146,17 @@ impl Storage {
145
146
version : & str ,
146
147
path : & str ,
147
148
archive_storage : bool ,
149
+ fetch_time : & mut RenderingTimesRecorder ,
148
150
) -> Result < Blob > {
149
151
Ok ( if archive_storage {
150
152
self . get_from_archive (
151
153
& rustdoc_archive_path ( name, version) ,
152
154
path,
153
155
self . max_file_size_for ( path) ,
156
+ Some ( fetch_time) ,
154
157
) ?
155
158
} else {
159
+ fetch_time. step ( "fetch from storage" ) ;
156
160
// Add rustdoc prefix, name and version to the path for accessing the file stored in the database
157
161
let remote_path = format ! ( "rustdoc/{}/{}/{}" , name, version, path) ;
158
162
self . get ( & remote_path, self . max_file_size_for ( path) ) ?
@@ -171,6 +175,7 @@ impl Storage {
171
175
& source_archive_path ( name, version) ,
172
176
path,
173
177
self . max_file_size_for ( path) ,
178
+ None ,
174
179
) ?
175
180
} else {
176
181
let remote_path = format ! ( "sources/{}/{}/{}" , name, version, path) ;
@@ -270,10 +275,17 @@ impl Storage {
270
275
archive_path : & str ,
271
276
path : & str ,
272
277
max_size : usize ,
278
+ mut fetch_time : Option < & mut RenderingTimesRecorder > ,
273
279
) -> Result < Blob > {
280
+ if let Some ( ref mut t) = fetch_time {
281
+ t. step ( "find path in index" ) ;
282
+ }
274
283
let index = self . get_index_for ( archive_path) ?;
275
284
let info = index. find_file ( path) ?;
276
285
286
+ if let Some ( t) = fetch_time {
287
+ t. step ( "range request" ) ;
288
+ }
277
289
let blob = self . get_range (
278
290
archive_path,
279
291
max_size,
@@ -790,12 +802,14 @@ mod backend_tests {
790
802
assert ! ( local_index_location. exists( ) ) ;
791
803
assert ! ( storage. exists_in_archive( "folder/test.zip" , "src/main.rs" ) ?) ;
792
804
793
- let file = storage. get_from_archive ( "folder/test.zip" , "Cargo.toml" , std:: usize:: MAX ) ?;
805
+ let file =
806
+ storage. get_from_archive ( "folder/test.zip" , "Cargo.toml" , std:: usize:: MAX , None ) ?;
794
807
assert_eq ! ( file. content, b"data" ) ;
795
808
assert_eq ! ( file. mime, "text/toml" ) ;
796
809
assert_eq ! ( file. path, "folder/test.zip/Cargo.toml" ) ;
797
810
798
- let file = storage. get_from_archive ( "folder/test.zip" , "src/main.rs" , std:: usize:: MAX ) ?;
811
+ let file =
812
+ storage. get_from_archive ( "folder/test.zip" , "src/main.rs" , std:: usize:: MAX , None ) ?;
799
813
assert_eq ! ( file. content, b"data" ) ;
800
814
assert_eq ! ( file. mime, "text/rust" ) ;
801
815
assert_eq ! ( file. path, "folder/test.zip/src/main.rs" ) ;
0 commit comments