Skip to content

Commit 4ed23c0

Browse files
GuillaumeGomezsyphar
authored andcommitted
Remove unused rustc_resource_suffix tera function and TemplateContext type
1 parent 2582dbe commit 4ed23c0

File tree

4 files changed

+9
-48
lines changed

4 files changed

+9
-48
lines changed

src/test/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -598,8 +598,7 @@ impl TestFrontend {
598598
}
599599

600600
debug!("loading template data");
601-
let template_data =
602-
Arc::new(TemplateData::new(&mut context.pool().unwrap().get().unwrap(), 1).unwrap());
601+
let template_data = Arc::new(TemplateData::new(1).unwrap());
603602

604603
debug!("binding local TCP port for axum");
605604
let axum_listener =

src/web/mod.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -344,10 +344,7 @@ pub fn start_background_metrics_webserver(
344344

345345
#[instrument(skip_all)]
346346
pub fn start_web_server(addr: Option<SocketAddr>, context: &dyn Context) -> Result<(), Error> {
347-
let template_data = Arc::new(TemplateData::new(
348-
&mut *context.pool()?.get()?,
349-
context.config()?.render_threads,
350-
)?);
347+
let template_data = Arc::new(TemplateData::new(context.config()?.render_threads)?);
351348

352349
let axum_addr = addr.unwrap_or(DEFAULT_BIND);
353350

src/web/page/templates.rs

+7-34
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
1-
use crate::{
2-
error::Result,
3-
utils::{get_config, ConfigName},
4-
};
1+
use crate::error::Result;
52
use anyhow::Context;
63
use chrono::{DateTime, Utc};
74
use path_slash::PathExt;
8-
use postgres::Client;
95
use serde_json::Value;
106
use std::{collections::HashMap, fmt, path::PathBuf, sync::Arc};
117
use tera::{Result as TeraResult, Tera};
12-
use tracing::{error, trace};
8+
use tracing::trace;
139
use walkdir::WalkDir;
1410

1511
const TEMPLATES_DIRECTORY: &str = "templates";
@@ -31,11 +27,11 @@ pub(crate) struct TemplateData {
3127
}
3228

3329
impl TemplateData {
34-
pub(crate) fn new(conn: &mut Client, num_threads: usize) -> Result<Self> {
30+
pub(crate) fn new(num_threads: usize) -> Result<Self> {
3531
trace!("Loading templates");
3632

3733
let data = Self {
38-
templates: load_templates(conn)?,
34+
templates: load_templates()?,
3935
rendering_threadpool: rayon::ThreadPoolBuilder::new()
4036
.num_threads(num_threads)
4137
.thread_name(move |idx| format!("docsrs-render {idx}"))
@@ -77,15 +73,7 @@ impl TemplateData {
7773
}
7874
}
7975

80-
fn load_rustc_resource_suffix(conn: &mut Client) -> Result<String> {
81-
if let Some(vers_str) = get_config::<String>(conn, ConfigName::RustcVersion)? {
82-
return crate::utils::parse_rustc_version(vers_str);
83-
}
84-
85-
anyhow::bail!("failed to parse the rustc version");
86-
}
87-
88-
fn load_templates(conn: &mut Client) -> Result<Tera> {
76+
fn load_templates() -> Result<Tera> {
8977
// This uses a custom function to find the templates in the filesystem instead of Tera's
9078
// builtin way (passing a glob expression to Tera::new), speeding up the startup of the
9179
// application and running the tests.
@@ -115,19 +103,6 @@ fn load_templates(conn: &mut Client) -> Result<Tera> {
115103
"docsrs_version",
116104
Value::String(crate::BUILD_VERSION.into()),
117105
);
118-
// This function will return the resource suffix of the latest nightly used to build
119-
// documentation on docs.rs, or ??? if no resource suffix was found.
120-
ReturnValue::add_function_to(
121-
&mut tera,
122-
"rustc_resource_suffix",
123-
Value::String(load_rustc_resource_suffix(conn).unwrap_or_else(|err| {
124-
error!("Failed to load rustc resource suffix: {:?}", err);
125-
// This is not fatal because the server might be started before essential files are
126-
// generated during development. Returning "???" provides a degraded UX, but allows the
127-
// server to start every time.
128-
String::from("???")
129-
})),
130-
);
131106

132107
// Custom filters
133108
tera.register_filter("timeformat", timeformat);
@@ -376,10 +351,8 @@ mod tests {
376351

377352
#[test]
378353
fn test_templates_are_valid() {
379-
crate::test::wrapper(|env| {
380-
let db = env.db();
381-
382-
let tera = load_templates(&mut db.conn()).unwrap();
354+
crate::test::wrapper(|_| {
355+
let tera = load_templates().unwrap();
383356
tera.check_macro_files().unwrap();
384357

385358
Ok(())

src/web/page/web_page.rs

-8
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use axum::{
99
};
1010
use futures_util::future::{BoxFuture, FutureExt};
1111
use http::header::CONTENT_LENGTH;
12-
use serde::Serialize;
1312
use std::sync::Arc;
1413
use tera::Context;
1514

@@ -111,13 +110,6 @@ macro_rules! impl_axum_webpage {
111110
};
112111
}
113112

114-
#[derive(Serialize)]
115-
struct TemplateContext<'a, T> {
116-
csp_nonce: &'a str,
117-
#[serde(flatten)]
118-
page: &'a T,
119-
}
120-
121113
/// adding this to the axum response extensions will lead
122114
/// to the template being rendered, adding the csp_nonce to
123115
/// the context.

0 commit comments

Comments
 (0)