Skip to content

Commit f9c5ffd

Browse files
committed
use crates.io search to search crates
1 parent 06dfd05 commit f9c5ffd

File tree

6 files changed

+479
-503
lines changed

6 files changed

+479
-503
lines changed

src/test/fakes.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,6 @@ impl<'a> FakeRelease<'a> {
9797
}
9898
}
9999

100-
pub(crate) fn downloads(mut self, downloads: i32) -> Self {
101-
self.registry_release_data.downloads = downloads;
102-
self
103-
}
104-
105100
pub(crate) fn description(mut self, new: impl Into<String>) -> Self {
106101
self.package.description = Some(new.into());
107102
self

src/utils/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ mod queue_builder;
2323
mod rustc_version;
2424
pub(crate) mod sized_buffer;
2525

26+
pub(crate) const APP_USER_AGENT: &str = concat!(
27+
env!("CARGO_PKG_NAME"),
28+
" ",
29+
include_str!(concat!(env!("OUT_DIR"), "/git_version"))
30+
);
31+
2632
pub(crate) fn report_error(err: &anyhow::Error) {
2733
if std::env::var("SENTRY_DSN").is_ok() {
2834
sentry_anyhow::capture_anyhow(err);

src/web/mod.rs

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ struct MatchVersion {
220220
/// dashes (`-`) replaced with underscores (`_`) and vice versa.
221221
pub corrected_name: Option<String>,
222222
pub version: MatchSemver,
223+
pub rustdoc_status: bool,
223224
}
224225

225226
impl MatchVersion {
@@ -284,9 +285,12 @@ fn match_version(
284285
.unwrap_or_else(|| "*".into());
285286

286287
let mut corrected_name = None;
287-
let versions: Vec<(String, i32, bool)> = {
288-
let query = "SELECT name, version, releases.id, releases.yanked
289-
FROM releases INNER JOIN crates ON releases.crate_id = crates.id
288+
let versions: Vec<(String, i32, bool, bool)> = {
289+
let query = "
290+
SELECT
291+
name, version, releases.id, releases.yanked, releases.rustdoc_status
292+
FROM releases
293+
INNER JOIN crates ON releases.crate_id = crates.id
290294
WHERE normalize_crate_name(name) = normalize_crate_name($1)";
291295

292296
let rows = conn.query(query, &[&name]).unwrap();
@@ -300,7 +304,7 @@ fn match_version(
300304
}
301305
};
302306

303-
rows.map(|row| (row.get(1), row.get(2), row.get(3)))
307+
rows.map(|row| (row.get(1), row.get(2), row.get(3), row.get(4)))
304308
.collect()
305309
};
306310

@@ -309,10 +313,13 @@ fn match_version(
309313
}
310314

311315
// first check for exact match, we can't expect users to use semver in query
312-
if let Some((version, id, _)) = versions.iter().find(|(vers, _, _)| vers == &req_version) {
316+
if let Some((version, id, _yanked, rustdoc_status)) =
317+
versions.iter().find(|(vers, _, _, _)| vers == &req_version)
318+
{
313319
return Ok(MatchVersion {
314320
corrected_name,
315321
version: MatchSemver::Exact((version.to_owned(), *id)),
322+
rustdoc_status: *rustdoc_status,
316323
});
317324
}
318325

@@ -321,9 +328,9 @@ fn match_version(
321328

322329
// we need to sort versions first
323330
let versions_sem = {
324-
let mut versions_sem: Vec<(Version, i32)> = Vec::with_capacity(versions.len());
331+
let mut versions_sem: Vec<(Version, i32, bool)> = Vec::with_capacity(versions.len());
325332

326-
for version in versions.iter().filter(|(_, _, yanked)| !yanked) {
333+
for version in versions.iter().filter(|(_, _, yanked, _)| !yanked) {
327334
// in theory a crate must always have a semver compatible version,
328335
// but check result just in case
329336
let version_sem = Version::parse(&version.0)
@@ -337,21 +344,22 @@ fn match_version(
337344
report_error(&err);
338345
Nope::InternalServerError
339346
})?;
340-
versions_sem.push((version_sem, version.1));
347+
versions_sem.push((version_sem, version.1, version.3));
341348
}
342349

343350
versions_sem.sort();
344351
versions_sem.reverse();
345352
versions_sem
346353
};
347354

348-
if let Some((version, id)) = versions_sem
355+
if let Some((version, id, rustdoc_status)) = versions_sem
349356
.iter()
350-
.find(|(vers, _)| req_sem_ver.matches(vers))
357+
.find(|(vers, _, _)| req_sem_ver.matches(vers))
351358
{
352359
return Ok(MatchVersion {
353360
corrected_name,
354361
version: MatchSemver::Semver((version.to_string(), *id)),
362+
rustdoc_status: *rustdoc_status,
355363
});
356364
}
357365

@@ -363,6 +371,7 @@ fn match_version(
363371
.map(|v| MatchVersion {
364372
corrected_name,
365373
version: MatchSemver::Semver((v.0.to_string(), v.1)),
374+
rustdoc_status: v.2,
366375
})
367376
.ok_or(Nope::VersionNotFound);
368377
}

0 commit comments

Comments
 (0)