Skip to content

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

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

Merged
merged 7 commits into from
Nov 29, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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