Skip to content

Commit 279bf16

Browse files
committed
WIP
1 parent 5f758e4 commit 279bf16

File tree

8 files changed

+33
-79
lines changed

8 files changed

+33
-79
lines changed

src/db/add_package.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ use crate::{
1010
use anyhow::{Context, anyhow};
1111
use derive_more::{Deref, Display};
1212
use futures_util::stream::TryStreamExt;
13-
use semver::VersionReq;
14-
use serde::Serialize;
1513
use serde::{Deserialize, Serialize};
1614
use serde_json::Value;
1715
use slug::slugify;

src/test/fakes.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,4 @@
11
use super::TestDatabase;
2-
3-
use crate::docbuilder::{DocCoverage, RUSTDOC_JSON_COMPRESSION_ALGORITHMS};
4-
use crate::error::Result;
5-
use crate::registry_api::{CrateData, CrateOwner, ReleaseData};
6-
use crate::storage::{
7-
AsyncStorage, CompressionAlgorithm, RustdocJsonFormatVersion, compress, rustdoc_archive_path,
8-
rustdoc_json_path, source_archive_path,
9-
};
10-
use crate::utils::{Dependency, MetadataPackage, cargo_metadata::Target};
112
use crate::{
123
db::{
134
BuildId, ReleaseId,
@@ -23,7 +14,7 @@ use crate::{
2314
AsyncStorage, CompressionAlgorithm, RustdocJsonFormatVersion, compress,
2415
rustdoc_archive_path, rustdoc_json_path, source_archive_path,
2516
},
26-
utils::{Dependency, MetadataPackage, Target},
17+
utils::{Dependency, MetadataPackage, cargo_metadata::Target},
2718
};
2819
use anyhow::{Context, bail};
2920
use base64::{Engine, engine::general_purpose::STANDARD as b64};

src/web/crate_details.rs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,13 @@
1-
use super::{MetaData, match_version};
21
use crate::{
32
AsyncStorage,
43
db::{
5-
BuildId, CrateId, ReleaseId,
4+
BuildId, CrateId, ReleaseDependency, ReleaseId,
65
types::{BuildStatus, version::Version},
76
},
87
impl_axum_webpage,
98
registry_api::OwnerKind,
109
storage::PathNotFoundError,
11-
utils::get_correct_docsrs_style_file,
12-
use crate::{
13-
AsyncStorage,
14-
db::{BuildId, CrateId, ReleaseDependency, ReleaseId, types::BuildStatus},
15-
impl_axum_webpage,
16-
registry_api::OwnerKind,
17-
storage::PathNotFoundError,
18-
utils::{Dependency, get_correct_docsrs_style_file, report_error},
10+
utils::{Dependency, get_correct_docsrs_style_file},
1911
web::{
2012
MatchedRelease, MetaData, ReqVersion,
2113
cache::CachePolicy,
@@ -26,7 +18,6 @@ use crate::{
2618
},
2719
headers::CanonicalUrl,
2820
match_version,
29-
page::templates::{RenderBrands, RenderRegular, RenderSolid, filters},
3021
},
3122
};
3223
use anyhow::{Context, Result, anyhow};
@@ -38,8 +29,6 @@ use axum::{
3829
use chrono::{DateTime, Utc};
3930
use futures_util::stream::TryStreamExt;
4031
use log::warn;
41-
use serde::Deserialize;
42-
use semver::Version;
4332
use serde_json::Value;
4433
use std::sync::Arc;
4534

src/web/extractors/rustdoc.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -816,9 +816,11 @@ fn find_static_route_suffix<'a, 'b>(route: &'a str, path: &'b str) -> Option<Str
816816
#[cfg(test)]
817817
mod tests {
818818
use super::*;
819-
use crate::test::{AxumResponseTestExt, AxumRouterTestExt};
819+
use crate::{
820+
db::types::version::Version,
821+
test::{AxumResponseTestExt, AxumRouterTestExt},
822+
};
820823
use axum::{Router, routing::get};
821-
use semver::Version;
822824
use test_case::test_case;
823825

824826
static KRATE: &str = "krate";

src/web/mod.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,11 @@
22
33
pub mod page;
44

5-
use crate::db::CrateId;
6-
use crate::db::ReleaseId;
7-
use crate::db::types::{BuildStatus, version::Version};
8-
use crate::utils::get_correct_docsrs_style_file;
9-
use crate::utils::report_error;
10-
use crate::web::page::templates::{RenderBrands, RenderSolid, filters};
115
use crate::{
12-
db::{CrateId, types::BuildStatus},
6+
db::{
7+
CrateId,
8+
types::{BuildStatus, version::Version},
9+
},
1310
utils::{get_correct_docsrs_style_file, report_error},
1411
web::page::templates::{RenderBrands, RenderSolid, filters},
1512
};

src/web/releases.rs

Lines changed: 17 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,13 @@ use base64::{Engine, engine::general_purpose::STANDARD as b64};
2626
use chrono::{DateTime, Utc};
2727
use futures_util::stream::TryStreamExt;
2828
use itertools::Itertools;
29-
use semver::Version;
3029
use serde::{Deserialize, Serialize};
3130
use sqlx::Row;
3231
use std::{
3332
collections::{BTreeMap, HashMap, HashSet},
3433
str,
3534
sync::Arc,
3635
};
37-
use tracing::warn;
3836
use tracing::{trace, warn};
3937
use url::form_urlencoded;
4038

@@ -120,28 +118,23 @@ pub(crate) async fn get_releases(
120118
}
121119
);
122120

123-
sqlx::query(query.as_str())
121+
Ok(sqlx::query(query.as_str())
124122
.bind(limit)
125123
.bind(offset)
126124
.bind(filter_failed)
127125
.fetch(conn)
128-
.err_into::<anyhow::Error>()
129-
.and_then(|row| async move {
130-
let version: semver::Version = row.get::<String, _>(1).parse()?;
131-
132-
Ok(Release {
133-
name: row.get(0),
134-
version,
135-
description: row.get(2),
136-
target_name: row.get(3),
137-
rustdoc_status: row.get::<Option<bool>, _>(4).unwrap_or(false),
138-
build_time: row.get(5),
139-
stars: row.get::<Option<i32>, _>(6).unwrap_or(0),
140-
has_unyanked_releases: None,
141-
})
126+
.map_ok(|row| Release {
127+
name: row.get(0),
128+
version: row.get(1),
129+
description: row.get(2),
130+
target_name: row.get(3),
131+
rustdoc_status: row.get::<Option<bool>, _>(4).unwrap_or(false),
132+
build_time: row.get(5),
133+
stars: row.get::<Option<i32>, _>(6).unwrap_or(0),
134+
has_unyanked_releases: None,
142135
})
143136
.try_collect()
144-
.await
137+
.await?)
145138
}
146139

147140
#[derive(Debug, Clone, PartialEq, Eq)]
@@ -211,22 +204,20 @@ async fn get_search_results(
211204
&names[..],
212205
)
213206
.fetch(&mut *conn)
214-
.err_into::<anyhow::Error>()
215-
.and_then(|row| async move {
216-
let version: semver::Version = row.version.parse()?;
217-
Ok((
207+
.map_ok(|row| {
208+
(
218209
row.name.clone(),
219210
Release {
220211
name: row.name,
221-
version,
212+
version: row.version,
222213
description: row.description,
223214
build_time: row.last_build_time,
224215
target_name: row.target_name,
225216
rustdoc_status: row.rustdoc_status.unwrap_or(false),
226217
stars: row.stars.unwrap_or(0),
227218
has_unyanked_releases: row.has_unyanked_releases,
228219
},
229-
))
220+
)
230221
})
231222
.try_collect()
232223
.await?;
@@ -765,14 +756,7 @@ pub(crate) async fn build_queue_handler(
765756
.fetch_all(&mut *conn)
766757
.await?
767758
.into_iter()
768-
.map(|rec| {
769-
(
770-
rec.name,
771-
rec.version
772-
.parse()
773-
.expect("all versions in the db are valid"),
774-
)
775-
})
759+
.map(|rec| (rec.name, rec.version))
776760
.collect();
777761

778762
let mut rebuild_queue = Vec::new();
@@ -782,11 +766,8 @@ pub(crate) async fn build_queue_handler(
782766
.into_iter()
783767
.filter(|krate| {
784768
!in_progress_builds.iter().any(|(name, version)| {
785-
// temporary, until I migrated the other version occurences to semver::Version
786-
// We know that in the DB we only have semver
787-
let krate_version: Version = krate.version.parse().unwrap();
788769
// use `.any` instead of `.contains` to avoid cloning name& version for the match
789-
*name == krate.name && *version == krate_version
770+
*name == krate.name && *version == krate.version
790771
})
791772
})
792773
.collect_vec();

src/web/rustdoc.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
33
use crate::{
44
AsyncStorage, Config, InstanceMetrics, RUSTDOC_STATIC_STORAGE_PREFIX,
5-
db::{Pool, types::version::Version},
65
storage::{
76
CompressionAlgorithm, RustdocJsonFormatVersion, StreamingBlob,
87
compression::compression_from_file_extension, rustdoc_archive_path, rustdoc_json_path,
@@ -36,7 +35,6 @@ use axum::{
3635
response::{IntoResponse, Response as AxumResponse},
3736
};
3837
use http::{HeaderValue, Uri, header};
39-
use http::{HeaderValue, header};
4038
use serde::Deserialize;
4139
use std::{
4240
collections::HashMap,
@@ -560,9 +558,9 @@ pub(crate) async fn rustdoc_html_server_handler(
560558
)
561559
{
562560
error!(
563-
krate = params.name,
561+
krate = params.name(),
564562
version = %krate.version,
565-
original_path = original_path.as_ref(),
563+
original_path = params.original_path().as_ref(),
566564
storage_path,
567565
"Couldn't find crate documentation root on storage.
568566
Something is wrong with the build."
@@ -895,6 +893,7 @@ mod test {
895893
use super::*;
896894
use crate::{
897895
Config,
896+
db::types::version::Version,
898897
docbuilder::RUSTDOC_JSON_COMPRESSION_ALGORITHMS,
899898
registry_api::{CrateOwner, OwnerKind},
900899
storage::compression::file_extension_for,

src/web/source.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use crate::{
22
AsyncStorage,
3-
db::BuildId,
4-
db::{BuildId, Pool, types::version::Version},
3+
db::{BuildId, types::version::Version},
54
impl_axum_webpage,
65
storage::PathNotFoundError,
76
web::{
@@ -23,8 +22,6 @@ use askama::Template;
2322
use axum::{Extension, response::IntoResponse};
2423
use axum_extra::headers::HeaderMapExt;
2524
use mime::Mime;
26-
use semver::Version;
27-
use serde::Deserialize;
2825
use std::{cmp::Ordering, sync::Arc};
2926
use tracing::instrument;
3027

@@ -245,7 +242,7 @@ pub(crate) async fn source_browser_handler(
245242
let (blob, is_file_too_large) = if !params.path_is_folder() {
246243
match storage
247244
.fetch_source_file(
248-
&params.name,
245+
&params.name(),
249246
&version,
250247
row.latest_build_id,
251248
inner_path,

0 commit comments

Comments
 (0)