Log file content type for Metadata Diffs in SCS

Summary: Phabricator uses the `commit_file_diffs` method to get metadata diff which it then uses to render information on the diff view page. With `ContentMetadataV2`, there are opportunities to avoid loading the  files in the commit in memory cause we already have the necessary metadata in hand. However, this optimization will only come in play when the file is non-textual (i.e. binary or non-UTF8). This diff adds logging changes to identify such requests from clients.

Reviewed By: YousefSalama

Differential Revision: D45395092

fbshipit-source-id: 19d2e7370adafff6e626387e1480249349da9be1
This commit is contained in:
Rajiv Sharma 2023-05-02 05:12:44 -07:00 committed by Facebook GitHub Bot
parent 56939ded8f
commit c64b1c775b

View File

@ -73,7 +73,32 @@ impl AddScubaResponse for thrift::RepoUploadFileContentResponse {
impl AddScubaResponse for thrift::CommitCompareResponse {}
impl AddScubaResponse for thrift::CommitFileDiffsResponse {}
impl AddScubaResponse for thrift::CommitFileDiffsResponse {
fn add_scuba_response(&self, scuba: &mut MononokeScubaSampleBuilder) {
let non_text_files = self
.path_diffs
.iter()
.filter_map(|response| match &response.diff {
thrift::Diff::metadata_diff(metadata) => match (
metadata.old_file_info.file_content_type,
metadata.new_file_info.file_content_type,
) {
(Some(old_file), Some(new_file)) => Some(vec![old_file, new_file]),
(Some(old_file), _) => Some(vec![old_file]),
(_, Some(new_file)) => Some(vec![new_file]),
_ => None,
},
_ => None,
})
.flatten()
.filter(|content_type| content_type.0 > 1) // Non-text or binary
.count();
// Only log if there are any actual non-textual files
if non_text_files > 0 {
scuba.add("non_text_files", non_text_files);
}
}
}
impl AddScubaResponse for thrift::CommitFindFilesResponse {}