Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

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

This file was deleted.

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

1 change: 0 additions & 1 deletion Cargo.lock

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

25 changes: 10 additions & 15 deletions crates/bin/docs_rs_builder/src/docbuilder/rustwide_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ use docs_rs_rustdoc_json::{
read_format_version_from_rustdoc_json,
};
use docs_rs_storage::{
AsyncStorage, Storage, compress, file_list_to_json, rustdoc_archive_path, rustdoc_json_path,
source_archive_path,
AsyncStorage, Storage, compress, rustdoc_archive_path, rustdoc_json_path, source_archive_path,
};
use docs_rs_types::{
BuildId, BuildStatus, CompressionAlgorithm, CrateId, KrateName, ReleaseId, Version,
Expand Down Expand Up @@ -640,23 +639,22 @@ impl RustwideBuilder {
let local_storage = tempfile::tempdir_in(&self.config.temp_dir)?;

let mut algs = HashSet::new();
let (source_files_list, source_size) = {
let source_stats = {
let _span = info_span!("adding sources into database").entered();
debug!("adding sources into database");
let temp_dir = tempfile::tempdir_in(&self.config.temp_dir)?;

krate.copy_source_to(&self.workspace, temp_dir.path())?;

let (files_list, new_alg) = self.runtime.block_on(
let stats = self.runtime.block_on(
self.storage
.store_all_in_archive(&source_archive_path(name, version), &temp_dir),
)?;

fs::remove_dir_all(temp_dir.path())?;

algs.insert(new_alg);
let source_size: u64 = files_list.iter().map(|info| info.size).sum();
(files_list, source_size)
algs.insert(stats.alg);
stats
};

let successful = build_dir
Expand Down Expand Up @@ -740,16 +738,15 @@ impl RustwideBuilder {
target_build_logs.insert(target, (target_res.build_log, successful));
}

let (file_list, new_alg) =
let doc_stats =
self.runtime.block_on(
self.storage.store_all_in_archive(
&rustdoc_archive_path(name, version),
local_storage.path(),
))?;
let documentation_size = file_list.iter().map(|info| info.size).sum::<u64>();
self.builder_metrics.documentation_size.record(documentation_size, &[]);
algs.insert(new_alg);
Some(documentation_size)
self.builder_metrics.documentation_size.record(doc_stats.original_size, &[]);
algs.insert(doc_stats.alg);
Some(doc_stats.original_size)
} else {
None
};
Expand Down Expand Up @@ -845,14 +842,13 @@ impl RustwideBuilder {
cargo_metadata,
&build.host_source_dir(),
&res.target,
file_list_to_json(source_files_list),
successful_targets,
&release_data,
has_docs,
has_examples,
algs,
repository,
source_size,
source_stats.original_size,
))?;

if let Some(repository_id) = repository {
Expand Down Expand Up @@ -1836,7 +1832,6 @@ mod tests {
},
Path::new("/unknown/"),
"x86_64-unknown-linux-gnu",
serde_json::Value::Array(vec![]),
vec![
"i686-pc-windows-msvc".into(),
"aarch64-unknown-linux-gnu".into(),
Expand Down
21 changes: 9 additions & 12 deletions crates/bin/docs_rs_import_release/src/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use docs_rs_rustdoc_json::{
RUSTDOC_JSON_COMPRESSION_ALGORITHMS, RustdocJsonFormatVersion,
read_format_version_from_rustdoc_json,
};
use docs_rs_storage::{AsyncStorage, file_list_to_json, rustdoc_archive_path, source_archive_path};
use docs_rs_storage::{AsyncStorage, rustdoc_archive_path, source_archive_path};
use docs_rs_storage::{compress, decompress, rustdoc_json_path};
use docs_rs_types::{
BuildId, BuildStatus, CrateId, KrateName, ReleaseId, ReqVersion, SimpleBuildError, Version,
Expand Down Expand Up @@ -113,15 +113,14 @@ async fn import_test_release_inner(
.await?;

let mut algs = HashSet::new();
let (source_files_list, source_size) = {
let source_stats = {
info!("writing source files to storage...");
let (files_list, new_alg) = storage
let stats = storage
.store_all_in_archive(&source_archive_path(name, version), &source_dir)
.await?;

algs.insert(new_alg);
let source_size: u64 = files_list.iter().map(|info| info.size).sum();
(files_list, source_size)
algs.insert(stats.alg);
stats
};

let registry_data = registry_api
Expand Down Expand Up @@ -178,11 +177,10 @@ async fn import_test_release_inner(
}

info!("writing rustdoc files to storage...");
let (rustdoc_file_list, new_alg) = storage
let doc_stats = storage
.store_all_in_archive(&rustdoc_archive_path(name, version), &rustdoc_dir)
.await?;
let documentation_size: u64 = rustdoc_file_list.iter().map(|info| info.size).sum();
algs.insert(new_alg);
algs.insert(doc_stats.alg);

info!("loading repository stats...");
let repository_id = repository_stats
Expand Down Expand Up @@ -232,14 +230,13 @@ async fn import_test_release_inner(
cargo_metadata.root(),
&source_dir,
default_target,
file_list_to_json(source_files_list),
all_targets,
&registry_data,
true,
false, // FIXME: real has_examples?
algs,
repository_id,
source_size,
source_stats.original_size,
)
.await?;

Expand All @@ -249,7 +246,7 @@ async fn import_test_release_inner(
"rustc 1.95.0-nightly (873d4682c 2026-01-25)",
BUILD_VERSION,
BuildStatus::Success,
Some(documentation_size),
Some(doc_stats.original_size),
None,
None::<&SimpleBuildError>,
)
Expand Down
32 changes: 0 additions & 32 deletions crates/bin/docs_rs_web/src/handlers/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -425,38 +425,6 @@ mod tests {
});
}

#[test]
fn empty_file_list_dont_break_the_view() {
async_wrapper(|env| async move {
let release_id = env
.fake_release()
.await
.name("fake")
.version("0.1.0")
.source_file("README.md", b"hello")
.create()
.await?;

let path = "/crate/fake/0.1.0/source/README.md";
let web = env.web_app().await;
web.assert_success(path).await?;

let mut conn = env.async_conn().await?;
sqlx::query!(
"UPDATE releases
SET files = NULL
WHERE id = $1",
release_id.0,
)
.execute(&mut *conn)
.await?;

assert!(web.get(path).await?.status().is_success());

Ok(())
});
}

#[test]
fn latest_contains_links_to_latest() {
async_wrapper(|env| async move {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ALTER TABLE releases
ADD COLUMN archive_storage BOOL NOT NULL DEFAULT TRUE,
ADD COLUMN files JSON ;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ALTER TABLE releases
DROP COLUMN files,
DROP COLUMN archive_storage;
29 changes: 10 additions & 19 deletions crates/lib/docs_rs_database/src/releases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use docs_rs_types::{
};
use docs_rs_utils::rustc_version::parse_rustc_date;
use futures_util::stream::TryStreamExt;
use serde_json::Value;
use slug::slugify;
use std::{
collections::{HashMap, HashSet},
Expand All @@ -21,19 +20,15 @@ use tracing::{debug, error, info, instrument};
/// Adds a package into database.
///
/// Package must be built first.
///
/// NOTE: `source_files` refers to the files originally in the crate,
/// not the files generated by rustdoc.
#[allow(clippy::too_many_arguments)]
#[instrument(skip(conn, compression_algorithms, source_files))]
#[instrument(skip(conn, compression_algorithms))]
pub async fn finish_release(
conn: &mut sqlx::PgConnection,
crate_id: CrateId,
release_id: ReleaseId,
metadata_pkg: &MetadataPackage,
source_dir: impl AsRef<Path> + fmt::Debug,
default_target: &str,
source_files: Value,
doc_targets: Vec<String>,
registry_data: &ReleaseData,
has_docs: bool,
Expand Down Expand Up @@ -72,14 +67,13 @@ pub async fn finish_release(
keywords = $14,
have_examples = $15,
downloads = $16,
files = $17,
doc_targets = $18,
is_library = $19,
documentation_url = $20,
default_target = $21,
features = $22,
repository_id = $23,
source_size = $24
doc_targets = $17,
is_library = $18,
documentation_url = $19,
default_target = $20,
features = $21,
repository_id = $22,
source_size = $23
WHERE id = $1"#,
release_id.0,
registry_data.release_time,
Expand All @@ -97,7 +91,6 @@ pub async fn finish_release(
serde_json::to_value(&metadata_pkg.keywords)?,
has_examples,
registry_data.downloads,
source_files,
serde_json::to_value(doc_targets)?,
is_library,
metadata_pkg.documentation,
Expand Down Expand Up @@ -337,8 +330,8 @@ pub async fn initialize_release(
version: &Version,
) -> Result<ReleaseId> {
let release_id = sqlx::query_scalar!(
r#"INSERT INTO releases (crate_id, version, archive_storage)
VALUES ($1, $2, TRUE)
r#"INSERT INTO releases (crate_id, version)
VALUES ($1, $2)
ON CONFLICT (crate_id, version) DO UPDATE
SET -- this `SET` is needed so the id is always returned.
version = EXCLUDED.version
Expand Down Expand Up @@ -697,7 +690,6 @@ mod test {
},
tempdir.path(),
DEFAULT_TARGET,
Value::Array(vec![]),
vec![DEFAULT_TARGET.to_string()],
&ReleaseData::default(),
true,
Expand Down Expand Up @@ -1471,7 +1463,6 @@ mod test {
},
tempdir.path(),
DEFAULT_TARGET,
Value::Array(vec![]),
vec![DEFAULT_TARGET.to_string()],
&ReleaseData::default(),
true,
Expand Down
1 change: 0 additions & 1 deletion crates/lib/docs_rs_storage/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ mime = { workspace = true }
moka = { version = "0.12.14", features = ["future"] }
opentelemetry = { workspace = true }
rand = { workspace = true, optional = true }
serde_json = { workspace = true }
sqlx = { workspace = true } # for sqlite
strum = { workspace = true }
tempfile = { workspace = true }
Expand Down
16 changes: 0 additions & 16 deletions crates/lib/docs_rs_storage/src/file.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use docs_rs_mimes::detect_mime;
use mime::Mime;
use serde_json::Value;
use std::path::PathBuf;

/// represents a file path from our source or documentation builds.
Expand All @@ -17,21 +16,6 @@ impl FileEntry {
}
}

pub fn file_list_to_json(files: impl IntoIterator<Item = FileEntry>) -> Value {
Value::Array(
files
.into_iter()
.map(|info| {
Value::Array(vec![
Value::String(info.mime().as_ref().to_string()),
Value::String(info.path.into_os_string().into_string().unwrap()),
Value::Number(info.size.into()),
])
})
.collect(),
)
}

#[derive(Debug, Clone, Eq)]
pub enum FolderEntry {
File(String, Mime),
Expand Down
4 changes: 3 additions & 1 deletion crates/lib/docs_rs_storage/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ mod config;
pub(crate) mod errors;
mod file;
mod metrics;
mod result;
pub(crate) mod storage;
#[cfg(any(test, feature = "testing"))]
pub mod testing;
Expand All @@ -16,7 +17,8 @@ pub use blob::{Blob, BlobUpload, StreamingBlob};
pub use compression::{compress, compress_async, decompress};
pub use config::Config;
pub use errors::{PathNotFoundError, SizeLimitReached};
pub use file::{FileEntry, FolderEntry, file_list_to_json};
pub use file::{FileEntry, FolderEntry};
pub use result::ArchiveStatistics;
pub use storage::blocking::Storage;
pub use storage::non_blocking::AsyncStorage;
pub use types::StorageKind;
Expand Down
Loading
Loading