Skip to content

Commit d8a2275

Browse files
jyn514Joshua Nelson
authored andcommitted
Update postgres to 0.17
``` $ cargo update -p postgres Updating crates.io index Removing base64 v0.6.0 Removing block-buffer v0.3.3 Removing byte-tools v0.2.0 Removing bytes v0.4.12 Adding cloudabi v0.1.0 Removing crypto-mac v0.5.2 Removing digest v0.7.6 Updating fallible-iterator v0.1.6 -> v0.2.0 Removing fuchsia-cprng v0.1.1 Removing generic-array v0.9.0 Removing hex v0.2.0 Removing hmac v0.5.0 Adding instant v0.1.6 Updating libc v0.2.70 -> v0.2.74 Adding lock_api v0.4.1 Removing md5 v0.3.8 Adding parking_lot v0.11.0 Adding parking_lot_core v0.8.0 Removing phf v0.7.24 Removing phf_shared v0.7.24 Updating postgres v0.15.2 -> v0.17.5 Updating postgres-protocol v0.3.2 -> v0.5.2 Removing postgres-shared v0.4.2 Adding postgres-types v0.1.2 Updating r2d2_postgres v0.14.0 -> v0.16.0 Removing rand v0.3.23 Removing rand v0.4.6 Removing rand_core v0.3.1 Removing rand_core v0.4.2 Removing rdrand v0.4.0 Removing safemem v0.2.0 Updating schemamama_postgres v0.2.4 -> v0.3.0 Removing sha2 v0.7.1 Removing siphasher v0.2.3 Adding tokio-postgres v0.5.5 ``` - Change &Connection to &mut Connection - Add `NoTls` type parameter to connection manager - Use `String.as_str()` instead of `&String` to help type inference - Temporarily `use Client as Connection` - Use `row.try_get()` instead of `row.get_opt()` - Use `rows[0]` instead of `rows.get(0)` - Various other small changes
1 parent 470b448 commit d8a2275

28 files changed

+422
-502
lines changed

Cargo.lock

Lines changed: 155 additions & 266 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ semver = { version = "0.9", features = ["serde"] }
1818
slug = "=0.1.1"
1919
env_logger = "0.7"
2020
r2d2 = "0.8"
21-
r2d2_postgres = "0.14"
21+
r2d2_postgres = "0.16"
2222
# iron needs url@1, but it reexports it as iron::url, so we can start using
2323
# url@2 for other usecases
2424
url = { version = "2.1.1", features = ["serde"] }
@@ -29,7 +29,7 @@ comrak = { version = "0.8", default-features = false }
2929
toml = "0.5"
3030
kuchiki = "0.8"
3131
schemamama = "0.3"
32-
schemamama_postgres = "0.2"
32+
schemamama_postgres = "0.3"
3333
systemstat = "0.1.4"
3434
prometheus = { version = "0.7.0", default-features = false }
3535
rustwide = "0.7.1"
@@ -72,8 +72,8 @@ chrono = { version = "0.4.11", features = ["serde"] }
7272
time = "0.1" # TODO: Remove once `iron` is removed
7373

7474
[dependencies.postgres]
75-
version = "0.15"
76-
features = ["with-chrono", "with-serde_json"]
75+
version = "0.17"
76+
features = ["with-chrono-0_4", "with-serde_json-1"]
7777

7878
[target.'cfg(target_os = "linux")'.dependencies]
7979
# Process information

src/bin/cratesfyi.rs

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -216,12 +216,12 @@ impl PrioritySubcommand {
216216
pub fn handle_args(self, ctx: Context) -> Result<(), Error> {
217217
match self {
218218
Self::Set { pattern, priority } => {
219-
set_crate_priority(&*ctx.conn()?, &pattern, priority)
219+
set_crate_priority(&mut *ctx.conn()?, &pattern, priority)
220220
.context("Could not set pattern's priority")?;
221221
}
222222

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

368368
Self::UpdateToolchain { only_first_time } => {
369369
if only_first_time {
370-
let conn = ctx
370+
let mut conn = ctx
371371
.pool()?
372372
.get()
373373
.context("failed to get a database connection")?;
@@ -449,7 +449,8 @@ impl DatabaseSubcommand {
449449
pub fn handle_args(self, ctx: Context) -> Result<(), Error> {
450450
match self {
451451
Self::Migrate { version } => {
452-
db::migrate(version, &*ctx.conn()?).context("Failed to run database migrations")?;
452+
db::migrate(version, &mut *ctx.conn()?)
453+
.context("Failed to run database migrations")?;
453454
}
454455

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

463464
db::update_crate_data_in_database(
464-
&*ctx.conn()?,
465+
&mut *ctx.conn()?,
465466
&name,
466467
&index.api().get_crate_data(&name)?,
467468
)?;
@@ -473,16 +474,18 @@ impl DatabaseSubcommand {
473474
}
474475

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

479482
Self::Delete {
480483
command: DeleteSubcommand::Version { name, version },
481-
} => db::delete_version(&*ctx.conn()?, &*ctx.storage()?, &name, &version)
484+
} => db::delete_version(&mut *ctx.conn()?, &*ctx.storage()?, &name, &version)
482485
.context("failed to delete the crate")?,
483486
Self::Delete {
484487
command: DeleteSubcommand::Crate { name },
485-
} => db::delete_crate(&*ctx.conn()?, &*ctx.storage()?, &name)
488+
} => db::delete_crate(&mut *ctx.conn()?, &*ctx.storage()?, &name)
486489
.context("failed to delete the crate")?,
487490
Self::Blacklist { command } => command.handle_args(ctx)?,
488491
}
@@ -512,19 +515,19 @@ enum BlacklistSubcommand {
512515

513516
impl BlacklistSubcommand {
514517
fn handle_args(self, ctx: Context) -> Result<(), Error> {
515-
let conn = &*ctx.conn()?;
518+
let mut conn = &mut *ctx.conn()?;
516519
match self {
517520
Self::List => {
518-
let crates = db::blacklist::list_crates(&conn)
521+
let crates = db::blacklist::list_crates(&mut conn)
519522
.context("failed to list crates on blacklist")?;
520523

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

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

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

603606
fn conn(
604607
&self,
605-
) -> Result<r2d2::PooledConnection<r2d2_postgres::PostgresConnectionManager>, Error> {
608+
) -> Result<
609+
r2d2::PooledConnection<r2d2_postgres::PostgresConnectionManager<postgres::NoTls>>,
610+
Error,
611+
> {
606612
Ok(self.pool()?.get()?)
607613
}
608614
}

src/build_queue.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,23 +39,23 @@ impl BuildQueue {
3939
"SELECT COUNT(*) FROM queue WHERE attempt < $1;",
4040
&[&self.max_attempts],
4141
)?;
42-
Ok(res.get(0).get::<_, i64>(0) as usize)
42+
Ok(res[0].get::<_, i64>(0) as usize)
4343
}
4444

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

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

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

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

107107
if attempt >= self.max_attempts {
108108
crate::web::metrics::FAILED_BUILDS.inc();

src/db/add_package.rs

Lines changed: 31 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::{
1212
utils::MetadataPackage,
1313
};
1414
use log::{debug, info};
15-
use postgres::Connection;
15+
use postgres::Client as Connection;
1616
use regex::Regex;
1717
use serde_json::Value;
1818
use slug::slugify;
@@ -25,7 +25,7 @@ use slug::slugify;
2525
/// not the files generated by rustdoc.
2626
#[allow(clippy::too_many_arguments)]
2727
pub(crate) fn add_package_into_database(
28-
conn: &Connection,
28+
conn: &mut Connection,
2929
metadata_pkg: &MetadataPackage,
3030
source_dir: &Path,
3131
res: &BuildResult,
@@ -38,7 +38,7 @@ pub(crate) fn add_package_into_database(
3838
compression_algorithms: std::collections::HashSet<CompressionAlgorithm>,
3939
) -> Result<i32> {
4040
debug!("Adding package into database");
41-
let crate_id = initialize_package_in_database(&conn, metadata_pkg)?;
41+
let crate_id = initialize_package_in_database(conn, metadata_pkg)?;
4242
let dependencies = convert_dependencies(metadata_pkg);
4343
let rustdoc = get_rustdoc(metadata_pkg, source_dir).unwrap_or(None);
4444
let readme = get_readme(metadata_pkg, source_dir).unwrap_or(None);
@@ -113,11 +113,11 @@ pub(crate) fn add_package_into_database(
113113
],
114114
)?;
115115

116-
let release_id: i32 = rows.get(0).get(0);
116+
let release_id: i32 = rows[0].get(0);
117117

118-
add_keywords_into_database(&conn, &metadata_pkg, release_id)?;
119-
add_authors_into_database(&conn, &metadata_pkg, release_id)?;
120-
add_compression_into_database(&conn, compression_algorithms.into_iter(), release_id)?;
118+
add_keywords_into_database(conn, &metadata_pkg, release_id)?;
119+
add_authors_into_database(conn, &metadata_pkg, release_id)?;
120+
add_compression_into_database(conn, compression_algorithms.into_iter(), release_id)?;
121121

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

133133
/// Adds a build into database
134134
pub(crate) fn add_build_into_database(
135-
conn: &Connection,
135+
conn: &mut Connection,
136136
release_id: i32,
137137
res: &BuildResult,
138138
) -> Result<i32> {
@@ -151,10 +151,10 @@ pub(crate) fn add_build_into_database(
151151
&res.build_log,
152152
],
153153
)?;
154-
Ok(rows.get(0).get(0))
154+
Ok(rows[0].get(0))
155155
}
156156

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

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

251251
/// Adds keywords into database
252252
fn add_keywords_into_database(
253-
conn: &Connection,
253+
conn: &mut Connection,
254254
pkg: &MetadataPackage,
255255
release_id: i32,
256256
) -> Result<()> {
@@ -259,14 +259,13 @@ fn add_keywords_into_database(
259259
let keyword_id: i32 = {
260260
let rows = conn.query("SELECT id FROM keywords WHERE slug = $1", &[&slug])?;
261261
if !rows.is_empty() {
262-
rows.get(0).get(0)
262+
rows[0].get(0)
263263
} else {
264264
conn.query(
265265
"INSERT INTO keywords (name, slug) VALUES ($1, $2) RETURNING id",
266266
&[&keyword, &slug],
267-
)?
268-
.get(0)
269-
.get(0)
267+
)?[0]
268+
.get(0)
270269
}
271270
};
272271

@@ -282,7 +281,7 @@ fn add_keywords_into_database(
282281

283282
/// Adds authors into database
284283
fn add_authors_into_database(
285-
conn: &Connection,
284+
conn: &mut Connection,
286285
pkg: &MetadataPackage,
287286
release_id: i32,
288287
) -> Result<()> {
@@ -304,15 +303,14 @@ fn add_authors_into_database(
304303
let author_id: i32 = {
305304
let rows = conn.query("SELECT id FROM authors WHERE slug = $1", &[&slug])?;
306305
if !rows.is_empty() {
307-
rows.get(0).get(0)
306+
rows[0].get(0)
308307
} else {
309308
conn.query(
310309
"INSERT INTO authors (name, email, slug) VALUES ($1, $2, $3)
311310
RETURNING id",
312311
&[&author, &email, &slug],
313-
)?
314-
.get(0)
315-
.get(0)
312+
)?[0]
313+
.get(0)
316314
}
317315
};
318316

@@ -328,15 +326,12 @@ fn add_authors_into_database(
328326
}
329327

330328
pub fn update_crate_data_in_database(
331-
conn: &Connection,
329+
conn: &mut Connection,
332330
name: &str,
333331
registry_data: &CrateData,
334332
) -> Result<()> {
335333
info!("Updating crate data for {}", name);
336-
let crate_id = conn
337-
.query("SELECT id FROM crates WHERE crates.name = $1", &[&name])?
338-
.get(0)
339-
.get(0);
334+
let crate_id = conn.query("SELECT id FROM crates WHERE crates.name = $1", &[&name])?[0].get(0);
340335

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

@@ -345,7 +340,7 @@ pub fn update_crate_data_in_database(
345340

346341
/// Adds owners into database
347342
fn update_owners_in_database(
348-
conn: &Connection,
343+
conn: &mut Connection,
349344
owners: &[CrateOwner],
350345
crate_id: i32,
351346
) -> Result<()> {
@@ -379,9 +374,8 @@ fn update_owners_in_database(
379374
RETURNING id
380375
",
381376
&[&owner.login, &owner.avatar, &owner.name, &owner.email],
382-
)?
383-
.get(0)
384-
.get(0)
377+
)?[0]
378+
.get(0)
385379
};
386380

387381
// add relationship
@@ -413,17 +407,21 @@ fn update_owners_in_database(
413407
}
414408

415409
/// Add the compression algorithms used for this crate to the database
416-
fn add_compression_into_database<I>(conn: &Connection, algorithms: I, release_id: i32) -> Result<()>
410+
fn add_compression_into_database<I>(
411+
conn: &mut Connection,
412+
algorithms: I,
413+
release_id: i32,
414+
) -> Result<()>
417415
where
418416
I: Iterator<Item = CompressionAlgorithm>,
419417
{
420418
let sql = "
421419
INSERT INTO compression_rels (release, algorithm)
422420
VALUES ($1, $2)
423421
ON CONFLICT DO NOTHING;";
424-
let prepared = conn.prepare_cached(sql)?;
422+
let prepared = conn.prepare(sql)?;
425423
for alg in algorithms {
426-
prepared.execute(&[&release_id, &(alg as i32)])?;
424+
conn.query(&prepared, &[&release_id, &(alg as i32)])?;
427425
}
428426
Ok(())
429427
}

0 commit comments

Comments
 (0)