Skip to content

Commit e7d5518

Browse files
sypharGuillaumeGomez
authored andcommitted
feat: track documentation size in database & metric
1 parent 97b3141 commit e7d5518

14 files changed

+329
-179
lines changed

.sqlx/query-d896b69c6f6061b0652862e2baa958d5cee193e28ec6532bc1b1fbb98cfc3f16.json renamed to .sqlx/query-0431f4fe27d903ad6af26ff36df056a9009e8746f8334ae32f0c900975968532.json

+4-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.sqlx/query-0da90d737b6bf2c1c1b0ab6b14c73c8363125578b1d6e30a99e70aa6bf7842c2.json

+57
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.sqlx/query-b2fa2e823f0f8e8fbd288cd0c102ad28a198463534efbefcf06f45c0f49872af.json renamed to .sqlx/query-c5315b9cdb9ffd0a939705f2700a73a3795cfe8e943716923ed9dfbaed3961af.json

+3-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.sqlx/query-c87fb1f05c8d726ab1211cf3a5d4e43ce08ac13c468ef4d90c28ab5fa8ec6ac7.json renamed to .sqlx/query-f011aefb83cbd26e7e83edbb3d280c554a9e2a64f0e7953c1e52939b24ccdafa.json

+18-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ALTER TABLE builds DROP COLUMN documentation_size;
2+
ALTER TABLE releases DROP COLUMN source_size;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ALTER TABLE builds ADD COLUMN documentation_size BIGINT;
2+
ALTER TABLE releases ADD COLUMN source_size BIGINT;

src/db/add_package.rs

+19-7
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use tracing::{debug, info, instrument};
2626
/// NOTE: `source_files` refers to the files originally in the crate,
2727
/// not the files generated by rustdoc.
2828
#[allow(clippy::too_many_arguments)]
29-
#[instrument(skip(conn))]
29+
#[instrument(skip(conn, compression_algorithms))]
3030
pub(crate) async fn add_package_into_database(
3131
conn: &mut sqlx::PgConnection,
3232
metadata_pkg: &MetadataPackage,
@@ -37,9 +37,10 @@ pub(crate) async fn add_package_into_database(
3737
registry_data: &ReleaseData,
3838
has_docs: bool,
3939
has_examples: bool,
40-
compression_algorithms: std::collections::HashSet<CompressionAlgorithm>,
40+
compression_algorithms: impl IntoIterator<Item = CompressionAlgorithm>,
4141
repository_id: Option<i32>,
4242
archive_storage: bool,
43+
source_size: u64,
4344
) -> Result<i32> {
4445
debug!("Adding package into database");
4546
let crate_id = initialize_crate(conn, &metadata_pkg.name).await?;
@@ -58,12 +59,12 @@ pub(crate) async fn add_package_into_database(
5859
keywords, have_examples, downloads, files,
5960
doc_targets, is_library,
6061
documentation_url, default_target, features,
61-
repository_id, archive_storage
62+
repository_id, archive_storage, source_size
6263
)
6364
VALUES (
6465
$1, $2, $3, $4, $5, $6, $7, $8, $9,
6566
$10, $11, $12, $13, $14, $15, $16, $17, $18,
66-
$19, $20, $21, $22, $23, $24, $25
67+
$19, $20, $21, $22, $23, $24, $25, $26
6768
)
6869
ON CONFLICT (crate_id, version) DO UPDATE
6970
SET release_time = $3,
@@ -88,7 +89,8 @@ pub(crate) async fn add_package_into_database(
8889
default_target = $22,
8990
features = $23,
9091
repository_id = $24,
91-
archive_storage = $25
92+
archive_storage = $25,
93+
source_size = $26
9294
RETURNING id",
9395
crate_id,
9496
&metadata_pkg.version,
@@ -114,7 +116,8 @@ pub(crate) async fn add_package_into_database(
114116
default_target,
115117
features as Vec<Feature>,
116118
repository_id,
117-
archive_storage
119+
archive_storage,
120+
source_size as i64,
118121
)
119122
.fetch_one(&mut *conn)
120123
.await?;
@@ -239,6 +242,7 @@ pub(crate) async fn finish_build(
239242
rustc_version: &str,
240243
docsrs_version: &str,
241244
build_status: BuildStatus,
245+
documentation_size: Option<u64>,
242246
errors: Option<&str>,
243247
) -> Result<()> {
244248
debug!("updating build after finishing");
@@ -252,15 +256,17 @@ pub(crate) async fn finish_build(
252256
build_status = $3,
253257
build_server = $4,
254258
errors = $5,
259+
documentation_size = $6,
255260
build_time = NOW()
256261
WHERE
257-
id = $6
262+
id = $7
258263
RETURNING rid",
259264
rustc_version,
260265
docsrs_version,
261266
build_status as BuildStatus,
262267
hostname.to_str().unwrap_or(""),
263268
errors,
269+
documentation_size.map(|v| v as i64),
264270
build_id,
265271
)
266272
.fetch_one(&mut *conn)
@@ -654,6 +660,7 @@ mod test {
654660
"rustc_version",
655661
"docsrs_version",
656662
BuildStatus::Success,
663+
Some(42),
657664
None,
658665
)
659666
.await?;
@@ -663,6 +670,7 @@ mod test {
663670
rustc_version,
664671
docsrs_version,
665672
build_status as "build_status: BuildStatus",
673+
documentation_size,
666674
errors
667675
FROM builds
668676
WHERE id = $1"#,
@@ -674,6 +682,7 @@ mod test {
674682
assert_eq!(row.rustc_version, Some("rustc_version".into()));
675683
assert_eq!(row.docsrs_version, Some("docsrs_version".into()));
676684
assert_eq!(row.build_status, BuildStatus::Success);
685+
assert_eq!(row.documentation_size, Some(42));
677686
assert!(row.errors.is_none());
678687

679688
Ok(())
@@ -694,6 +703,7 @@ mod test {
694703
"rustc_version",
695704
"docsrs_version",
696705
BuildStatus::Failure,
706+
None,
697707
Some("error message"),
698708
)
699709
.await?;
@@ -703,6 +713,7 @@ mod test {
703713
rustc_version,
704714
docsrs_version,
705715
build_status as "build_status: BuildStatus",
716+
documentation_size,
706717
errors
707718
FROM builds
708719
WHERE id = $1"#,
@@ -715,6 +726,7 @@ mod test {
715726
assert_eq!(row.docsrs_version, Some("docsrs_version".into()));
716727
assert_eq!(row.build_status, BuildStatus::Failure);
717728
assert_eq!(row.errors, Some("error message".into()));
729+
assert!(row.documentation_size.is_none());
718730

719731
Ok(())
720732
})

0 commit comments

Comments
 (0)