Skip to content

Switch from kuchiki to LOL_HTML #930

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Aug 3, 2020
105 changes: 105 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ backtrace = "0.3"
failure = { version = "0.1.3", features = ["backtrace"] }
comrak = { version = "0.3", default-features = false }
toml = "0.5"
kuchiki = "0.8"
schemamama = "0.3"
schemamama_postgres = "0.2"
systemstat = "0.1.4"
Expand All @@ -41,6 +40,7 @@ path-slash = "0.1.3"
once_cell = { version = "1.4.0", features = ["parking_lot"] }
base64 = "0.12.1"
strum = { version = "0.18.0", features = ["derive"] }
lol_html = "0.2"

# Async
tokio = { version = "0.2.22", features = ["rt-threaded"] }
Expand Down Expand Up @@ -82,6 +82,7 @@ procfs = "0.7"

[dev-dependencies]
criterion = "0.3"
kuchiki = "0.8"
rand = "0.7.3"

[[bench]]
Expand Down
7 changes: 6 additions & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ pub struct Config {
// Max size of the files served by the docs.rs frontend
pub(crate) max_file_size: usize,
pub(crate) max_file_size_html: usize,
// The most memory that can be used to parse an HTML file
pub(crate) max_parse_memory: usize,
}

impl Config {
Expand Down Expand Up @@ -55,7 +57,10 @@ impl Config {
github_accesstoken: maybe_env("CRATESFYI_GITHUB_ACCESSTOKEN")?,

max_file_size: env("DOCSRS_MAX_FILE_SIZE", 50 * 1024 * 1024)?,
max_file_size_html: env("DOCSRS_MAX_FILE_SIZE_HTML", 5 * 1024 * 1024)?,
max_file_size_html: env("DOCSRS_MAX_FILE_SIZE_HTML", 50 * 1024 * 1024)?,
// LOL HTML only uses as much memory as the size of the start tag!
// https://github.com/rust-lang/docs.rs/pull/930#issuecomment-667729380
max_parse_memory: env("DOCSRS_MAX_PARSE_MEMORY", 5 * 1024 * 1024)?,
})
}

Expand Down
14 changes: 12 additions & 2 deletions src/test/fakes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ pub(crate) struct FakeRelease<'a> {
readme: Option<&'a str>,
}

const DEFAULT_CONTENT: &[u8] =
b"<html><head></head><body>default content for test/fakes</body></html>";

impl<'a> FakeRelease<'a> {
pub(super) fn new(db: &'a TestDatabase, storage: Arc<Storage>) -> Self {
FakeRelease {
Expand Down Expand Up @@ -121,7 +124,14 @@ impl<'a> FakeRelease<'a> {
self
}

pub(crate) fn rustdoc_file(mut self, path: &'a str, data: &'a [u8]) -> Self {
/// Since we switched to LOL HTML, all data must have a valid <head> and <body>.
/// To avoid duplicating them in every test, this just makes up some content.
pub(crate) fn rustdoc_file(mut self, path: &'a str) -> Self {
self.rustdoc_files.push((path, DEFAULT_CONTENT));
self
}

pub(crate) fn rustdoc_file_with(mut self, path: &'a str, data: &'a [u8]) -> Self {
self.rustdoc_files.push((path, data));
self
}
Expand Down Expand Up @@ -217,7 +227,7 @@ impl<'a> FakeRelease<'a> {
let index = [&package.name, "index.html"].join("/");
let mut rustdoc_files = self.rustdoc_files;
if package.is_library() && !rustdoc_files.iter().any(|(path, _)| path == &index) {
rustdoc_files.push((&index, b"default index content"));
rustdoc_files.push((&index, DEFAULT_CONTENT));
}
for (source_path, data) in &self.source_files {
if source_path.starts_with("src/") {
Expand Down
Loading