Skip to content
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

Remove duplicate dependencies #929

Merged
merged 5 commits into from
Aug 3, 2020
Merged
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
767 changes: 168 additions & 599 deletions Cargo.lock

Large diffs are not rendered by default.

11 changes: 5 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@ semver = { version = "0.9", features = ["serde"] }
slug = "=0.1.1"
env_logger = "0.7"
r2d2 = "0.8"
r2d2_postgres = "0.14"
r2d2_postgres = "0.16"
# iron needs url@1, but it reexports it as iron::url, so we can start using
# url@2 for other usecases
url = { version = "2.1.1", features = ["serde"] }
badge = { path = "src/web/badge" }
backtrace = "0.3"
failure = { version = "0.1.3", features = ["backtrace"] }
comrak = { version = "0.3", default-features = false }
comrak = { version = "0.8", default-features = false }
toml = "0.5"
kuchiki = "0.8"
schemamama = "0.3"
schemamama_postgres = "0.2"
schemamama_postgres = "0.3"
systemstat = "0.1.4"
prometheus = { version = "0.7.0", default-features = false }
rustwide = "0.7.1"
Expand All @@ -56,7 +56,6 @@ serde_json = "1.0"
# iron dependencies
iron = "0.5"
router = "0.5"
params = "0.8"
staticfile = { version = "0.4", features = [ "cache" ] }
tempfile = "3.1.0"

Expand All @@ -73,8 +72,8 @@ chrono = { version = "0.4.11", features = ["serde"] }
time = "0.1" # TODO: Remove once `iron` is removed

[dependencies.postgres]
version = "0.15"
features = ["with-chrono", "with-serde_json"]
version = "0.17"
features = ["with-chrono-0_4", "with-serde_json-1"]

[target.'cfg(target_os = "linux")'.dependencies]
# Process information
Expand Down
34 changes: 20 additions & 14 deletions src/bin/cratesfyi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,12 +216,12 @@ impl PrioritySubcommand {
pub fn handle_args(self, ctx: Context) -> Result<(), Error> {
match self {
Self::Set { pattern, priority } => {
set_crate_priority(&*ctx.conn()?, &pattern, priority)
set_crate_priority(&mut *ctx.conn()?, &pattern, priority)
.context("Could not set pattern's priority")?;
}

Self::Remove { pattern } => {
if let Some(priority) = remove_crate_priority(&*ctx.conn()?, &pattern)
if let Some(priority) = remove_crate_priority(&mut *ctx.conn()?, &pattern)
.context("Could not remove pattern's priority")?
{
println!("Removed pattern with priority {}", priority);
Expand Down Expand Up @@ -367,7 +367,7 @@ impl BuildSubcommand {

Self::UpdateToolchain { only_first_time } => {
if only_first_time {
let conn = ctx
let mut conn = ctx
.pool()?
.get()
.context("failed to get a database connection")?;
Expand Down Expand Up @@ -449,7 +449,8 @@ impl DatabaseSubcommand {
pub fn handle_args(self, ctx: Context) -> Result<(), Error> {
match self {
Self::Migrate { version } => {
db::migrate(version, &*ctx.conn()?).context("Failed to run database migrations")?;
db::migrate(version, &mut *ctx.conn()?)
.context("Failed to run database migrations")?;
}

Self::UpdateGithubFields => {
Expand All @@ -461,7 +462,7 @@ impl DatabaseSubcommand {
let index = Index::new(&ctx.config()?.registry_index_path)?;

db::update_crate_data_in_database(
&*ctx.conn()?,
&mut *ctx.conn()?,
&name,
&index.api().get_crate_data(&name)?,
)?;
Expand All @@ -473,16 +474,18 @@ impl DatabaseSubcommand {
}

// FIXME: This is actually util command not database
Self::UpdateReleaseActivity => cratesfyi::utils::update_release_activity(&*ctx.conn()?)
.context("Failed to update release activity")?,
Self::UpdateReleaseActivity => {
cratesfyi::utils::update_release_activity(&mut *ctx.conn()?)
.context("Failed to update release activity")?
}

Self::Delete {
command: DeleteSubcommand::Version { name, version },
} => db::delete_version(&*ctx.conn()?, &*ctx.storage()?, &name, &version)
} => db::delete_version(&mut *ctx.conn()?, &*ctx.storage()?, &name, &version)
.context("failed to delete the crate")?,
Self::Delete {
command: DeleteSubcommand::Crate { name },
} => db::delete_crate(&*ctx.conn()?, &*ctx.storage()?, &name)
} => db::delete_crate(&mut *ctx.conn()?, &*ctx.storage()?, &name)
.context("failed to delete the crate")?,
Self::Blacklist { command } => command.handle_args(ctx)?,
}
Expand Down Expand Up @@ -512,19 +515,19 @@ enum BlacklistSubcommand {

impl BlacklistSubcommand {
fn handle_args(self, ctx: Context) -> Result<(), Error> {
let conn = &*ctx.conn()?;
let mut conn = &mut *ctx.conn()?;
match self {
Self::List => {
let crates = db::blacklist::list_crates(&conn)
let crates = db::blacklist::list_crates(&mut conn)
.context("failed to list crates on blacklist")?;

println!("{}", crates.join("\n"));
}

Self::Add { crate_name } => db::blacklist::add_crate(&conn, &crate_name)
Self::Add { crate_name } => db::blacklist::add_crate(&mut conn, &crate_name)
.context("failed to add crate to blacklist")?,

Self::Remove { crate_name } => db::blacklist::remove_crate(&conn, &crate_name)
Self::Remove { crate_name } => db::blacklist::remove_crate(&mut conn, &crate_name)
.context("failed to remove crate from blacklist")?,
}
Ok(())
Expand Down Expand Up @@ -602,7 +605,10 @@ impl Context {

fn conn(
&self,
) -> Result<r2d2::PooledConnection<r2d2_postgres::PostgresConnectionManager>, Error> {
) -> Result<
r2d2::PooledConnection<r2d2_postgres::PostgresConnectionManager<postgres::NoTls>>,
Error,
> {
Ok(self.pool()?.get()?)
}
}
10 changes: 5 additions & 5 deletions src/build_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,23 @@ impl BuildQueue {
"SELECT COUNT(*) FROM queue WHERE attempt < $1;",
&[&self.max_attempts],
)?;
Ok(res.get(0).get::<_, i64>(0) as usize)
Ok(res[0].get::<_, i64>(0) as usize)
}

pub(crate) fn prioritized_count(&self) -> Result<usize> {
let res = self.db.get()?.query(
"SELECT COUNT(*) FROM queue WHERE attempt < $1 AND priority <= 0;",
&[&self.max_attempts],
)?;
Ok(res.get(0).get::<_, i64>(0) as usize)
Ok(res[0].get::<_, i64>(0) as usize)
}

pub(crate) fn failed_count(&self) -> Result<usize> {
let res = self.db.get()?.query(
"SELECT COUNT(*) FROM queue WHERE attempt >= $1;",
&[&self.max_attempts],
)?;
Ok(res.get(0).get::<_, i64>(0) as usize)
Ok(res[0].get::<_, i64>(0) as usize)
}

pub(crate) fn queued_crates(&self) -> Result<Vec<QueuedCrate>> {
Expand All @@ -82,7 +82,7 @@ impl BuildQueue {
&self,
f: impl FnOnce(&QueuedCrate) -> Result<()>,
) -> Result<()> {
let conn = self.db.get()?;
let mut conn = self.db.get()?;

let queued = self.queued_crates()?;
let to_process = match queued.get(0) {
Expand All @@ -102,7 +102,7 @@ impl BuildQueue {
"UPDATE queue SET attempt = attempt + 1 WHERE id = $1 RETURNING attempt;",
&[&to_process.id],
)?;
let attempt: i32 = rows.get(0).get(0);
let attempt: i32 = rows[0].get(0);

if attempt >= self.max_attempts {
crate::web::metrics::FAILED_BUILDS.inc();
Expand Down
60 changes: 27 additions & 33 deletions src/db/add_package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::{
utils::MetadataPackage,
};
use log::{debug, info};
use postgres::Connection;
use postgres::Client;
use regex::Regex;
use serde_json::Value;
use slug::slugify;
Expand All @@ -25,7 +25,7 @@ use slug::slugify;
/// not the files generated by rustdoc.
#[allow(clippy::too_many_arguments)]
pub(crate) fn add_package_into_database(
conn: &Connection,
conn: &mut Client,
metadata_pkg: &MetadataPackage,
source_dir: &Path,
res: &BuildResult,
Expand All @@ -38,7 +38,7 @@ pub(crate) fn add_package_into_database(
compression_algorithms: std::collections::HashSet<CompressionAlgorithm>,
) -> Result<i32> {
debug!("Adding package into database");
let crate_id = initialize_package_in_database(&conn, metadata_pkg)?;
let crate_id = initialize_package_in_database(conn, metadata_pkg)?;
let dependencies = convert_dependencies(metadata_pkg);
let rustdoc = get_rustdoc(metadata_pkg, source_dir).unwrap_or(None);
let readme = get_readme(metadata_pkg, source_dir).unwrap_or(None);
Expand Down Expand Up @@ -113,11 +113,11 @@ pub(crate) fn add_package_into_database(
],
)?;

let release_id: i32 = rows.get(0).get(0);
let release_id: i32 = rows[0].get(0);

add_keywords_into_database(&conn, &metadata_pkg, release_id)?;
add_authors_into_database(&conn, &metadata_pkg, release_id)?;
add_compression_into_database(&conn, compression_algorithms.into_iter(), release_id)?;
add_keywords_into_database(conn, &metadata_pkg, release_id)?;
add_authors_into_database(conn, &metadata_pkg, release_id)?;
add_compression_into_database(conn, compression_algorithms.into_iter(), release_id)?;

// Update the crates table with the new release
conn.execute(
Expand All @@ -132,7 +132,7 @@ pub(crate) fn add_package_into_database(

/// Adds a build into database
pub(crate) fn add_build_into_database(
conn: &Connection,
conn: &mut Client,
release_id: i32,
res: &BuildResult,
) -> Result<i32> {
Expand All @@ -151,10 +151,10 @@ pub(crate) fn add_build_into_database(
&res.build_log,
],
)?;
Ok(rows.get(0).get(0))
Ok(rows[0].get(0))
}

fn initialize_package_in_database(conn: &Connection, pkg: &MetadataPackage) -> Result<i32> {
fn initialize_package_in_database(conn: &mut Client, pkg: &MetadataPackage) -> Result<i32> {
let mut rows = conn.query("SELECT id FROM crates WHERE name = $1", &[&pkg.name])?;
// insert crate into database if it is not exists
if rows.is_empty() {
Expand All @@ -163,7 +163,7 @@ fn initialize_package_in_database(conn: &Connection, pkg: &MetadataPackage) -> R
&[&pkg.name],
)?;
}
Ok(rows.get(0).get(0))
Ok(rows[0].get(0))
}

/// Convert dependencies into Vec<(String, String, String)>
Expand Down Expand Up @@ -250,7 +250,7 @@ fn read_rust_doc(file_path: &Path) -> Result<Option<String>> {

/// Adds keywords into database
fn add_keywords_into_database(
conn: &Connection,
conn: &mut Client,
pkg: &MetadataPackage,
release_id: i32,
) -> Result<()> {
Expand All @@ -259,14 +259,13 @@ fn add_keywords_into_database(
let keyword_id: i32 = {
let rows = conn.query("SELECT id FROM keywords WHERE slug = $1", &[&slug])?;
if !rows.is_empty() {
rows.get(0).get(0)
rows[0].get(0)
} else {
conn.query(
"INSERT INTO keywords (name, slug) VALUES ($1, $2) RETURNING id",
&[&keyword, &slug],
)?
.get(0)
.get(0)
)?[0]
.get(0)
}
};

Expand All @@ -282,7 +281,7 @@ fn add_keywords_into_database(

/// Adds authors into database
fn add_authors_into_database(
conn: &Connection,
conn: &mut Client,
pkg: &MetadataPackage,
release_id: i32,
) -> Result<()> {
Expand All @@ -304,15 +303,14 @@ fn add_authors_into_database(
let author_id: i32 = {
let rows = conn.query("SELECT id FROM authors WHERE slug = $1", &[&slug])?;
if !rows.is_empty() {
rows.get(0).get(0)
rows[0].get(0)
} else {
conn.query(
"INSERT INTO authors (name, email, slug) VALUES ($1, $2, $3)
RETURNING id",
&[&author, &email, &slug],
)?
.get(0)
.get(0)
)?[0]
.get(0)
}
};

Expand All @@ -328,15 +326,12 @@ fn add_authors_into_database(
}

pub fn update_crate_data_in_database(
conn: &Connection,
conn: &mut Client,
name: &str,
registry_data: &CrateData,
) -> Result<()> {
info!("Updating crate data for {}", name);
let crate_id = conn
.query("SELECT id FROM crates WHERE crates.name = $1", &[&name])?
.get(0)
.get(0);
let crate_id = conn.query("SELECT id FROM crates WHERE crates.name = $1", &[&name])?[0].get(0);

update_owners_in_database(conn, &registry_data.owners, crate_id)?;

Expand All @@ -345,7 +340,7 @@ pub fn update_crate_data_in_database(

/// Adds owners into database
fn update_owners_in_database(
conn: &Connection,
conn: &mut Client,
owners: &[CrateOwner],
crate_id: i32,
) -> Result<()> {
Expand Down Expand Up @@ -379,9 +374,8 @@ fn update_owners_in_database(
RETURNING id
",
&[&owner.login, &owner.avatar, &owner.name, &owner.email],
)?
.get(0)
.get(0)
)?[0]
.get(0)
};

// add relationship
Expand Down Expand Up @@ -413,17 +407,17 @@ fn update_owners_in_database(
}

/// Add the compression algorithms used for this crate to the database
fn add_compression_into_database<I>(conn: &Connection, algorithms: I, release_id: i32) -> Result<()>
fn add_compression_into_database<I>(conn: &mut Client, algorithms: I, release_id: i32) -> Result<()>
where
I: Iterator<Item = CompressionAlgorithm>,
{
let sql = "
INSERT INTO compression_rels (release, algorithm)
VALUES ($1, $2)
ON CONFLICT DO NOTHING;";
let prepared = conn.prepare_cached(sql)?;
let prepared = conn.prepare(sql)?;
for alg in algorithms {
prepared.execute(&[&release_id, &(alg as i32)])?;
conn.query(&prepared, &[&release_id, &(alg as i32)])?;
}
Ok(())
}
Loading