Skip to content

Commit

Permalink
change latest version ID on crate to match CrateDetails.latest_version
Browse files Browse the repository at this point in the history
  • Loading branch information
syphar committed Nov 7, 2021
1 parent 75f7a1c commit 3e7ec5b
Show file tree
Hide file tree
Showing 5 changed files with 245 additions and 149 deletions.
22 changes: 13 additions & 9 deletions src/db/add_package.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
use std::{
collections::{HashMap, HashSet},
fs,
io::{BufRead, BufReader},
path::Path,
};

use crate::{
db::types::Feature,
docbuilder::{BuildResult, DocCoverage},
error::Result,
index::api::{CrateData, CrateOwner, ReleaseData},
storage::CompressionAlgorithm,
utils::MetadataPackage,
web::crate_details::CrateDetails,
};
use anyhow::{anyhow, Context};
use log::{debug, info};
use postgres::Client;
use serde_json::Value;
use slug::slugify;
use std::{
collections::{HashMap, HashSet},
fs,
io::{BufRead, BufReader},
path::Path,
};

/// Adds a package into database.
///
Expand Down Expand Up @@ -127,12 +128,15 @@ pub(crate) fn add_package_into_database(
add_keywords_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
let crate_details = CrateDetails::new(conn, &metadata_pkg.name, &metadata_pkg.version, None)
.with_context(|| anyhow!("error when fetching crate-details"))?
.ok_or_else(|| anyhow!("crate details not found directly after creating them"))?;

conn.execute(
"UPDATE crates
SET latest_version_id = $2
WHERE id = $1",
&[&crate_id, &release_id],
&[&crate_id, &crate_details.latest_release().id],
)?;

Ok(release_id)
Expand Down
Loading

0 comments on commit 3e7ec5b

Please sign in to comment.