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

change latest version ID on crate to match CrateDetails.latest_version #1546

Merged
merged 7 commits into from
Nov 29, 2021
28 changes: 19 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,21 @@ 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,
&metadata_pkg.version,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jyn514 @jsha without me digging into #1527,
is it correct just to use the version twice?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that's fine, it only matters for the frontend templates.

None,
)
.context("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