Skip to content

Commit dbe7be4

Browse files
authored
perf(google_drive): generate EXPORT_MIME_TYPES at compile time (#593)
1 parent 4968277 commit dbe7be4

File tree

3 files changed

+47
-46
lines changed

3 files changed

+47
-46
lines changed

Cargo.lock

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ tower-http = { version = "0.6.2", features = ["cors", "trace"] }
5050
indexmap = { version = "2.8.0", features = ["serde"] }
5151
blake2 = "0.10.6"
5252
pgvector = { version = "0.4.0", features = ["sqlx"] }
53+
phf = { version = "0.11.3", features = ["macros"] }
5354
indenter = "0.3.3"
5455
itertools = "0.14.0"
5556
derivative = "2.2.0"

src/ops/sources/google_drive.rs

Lines changed: 31 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
use chrono::Duration;
22
use google_drive3::{
3-
api::{File, Scope},
4-
yup_oauth2::{read_service_account_key, ServiceAccountAuthenticator},
53
DriveHub,
4+
api::{File, Scope},
5+
yup_oauth2::{ServiceAccountAuthenticator, read_service_account_key},
66
};
77
use http_body_util::BodyExt;
88
use hyper_rustls::HttpsConnector;
99
use hyper_util::client::legacy::connect::HttpConnector;
10+
use phf::phf_map;
1011

1112
use crate::base::field_attrs;
1213
use crate::ops::sdk::*;
@@ -18,45 +19,33 @@ struct ExportMimeType {
1819

1920
const FOLDER_MIME_TYPE: &str = "application/vnd.google-apps.folder";
2021
const FILE_MIME_TYPE: &str = "application/vnd.google-apps.file";
21-
static EXPORT_MIME_TYPES: LazyLock<HashMap<&'static str, ExportMimeType>> = LazyLock::new(|| {
22-
HashMap::from([
23-
(
24-
"application/vnd.google-apps.document",
25-
ExportMimeType {
26-
text: "text/markdown",
27-
binary: "application/pdf",
28-
},
29-
),
30-
(
31-
"application/vnd.google-apps.spreadsheet",
32-
ExportMimeType {
33-
text: "text/csv",
34-
binary: "application/pdf",
35-
},
36-
),
37-
(
38-
"application/vnd.google-apps.presentation",
39-
ExportMimeType {
40-
text: "text/plain",
41-
binary: "application/pdf",
42-
},
43-
),
44-
(
45-
"application/vnd.google-apps.drawing",
46-
ExportMimeType {
47-
text: "image/svg+xml",
48-
binary: "image/png",
49-
},
50-
),
51-
(
52-
"application/vnd.google-apps.script",
53-
ExportMimeType {
54-
text: "application/vnd.google-apps.script+json",
55-
binary: "application/vnd.google-apps.script+json",
56-
},
57-
),
58-
])
59-
});
22+
static EXPORT_MIME_TYPES: phf::Map<&'static str, ExportMimeType> = phf_map! {
23+
"application/vnd.google-apps.document" =>
24+
ExportMimeType {
25+
text: "text/markdown",
26+
binary: "application/pdf",
27+
},
28+
"application/vnd.google-apps.spreadsheet" =>
29+
ExportMimeType {
30+
text: "text/csv",
31+
binary: "application/pdf",
32+
},
33+
"application/vnd.google-apps.presentation" =>
34+
ExportMimeType {
35+
text: "text/plain",
36+
binary: "application/pdf",
37+
},
38+
"application/vnd.google-apps.drawing" =>
39+
ExportMimeType {
40+
text: "image/svg+xml",
41+
binary: "image/png",
42+
},
43+
"application/vnd.google-apps.script" =>
44+
ExportMimeType {
45+
text: "application/vnd.google-apps.script+json",
46+
binary: "application/vnd.google-apps.script+json",
47+
},
48+
};
6049

6150
fn is_supported_file_type(mime_type: &str) -> bool {
6251
!mime_type.starts_with("application/vnd.google-apps.")
@@ -291,11 +280,7 @@ impl<T> ResultExt<T> for google_drive3::Result<T> {
291280
}
292281

293282
fn optional_modified_time(include_ordinal: bool) -> &'static str {
294-
if include_ordinal {
295-
",modifiedTime"
296-
} else {
297-
""
298-
}
283+
if include_ordinal { ",modifiedTime" } else { "" }
299284
}
300285

301286
#[async_trait]

0 commit comments

Comments
 (0)