Skip to content

Commit 077ee97

Browse files
authored
change latest version ID on crate to match CrateDetails.latest_version (#1546)
1 parent 6085dba commit 077ee97

File tree

6 files changed

+233
-168
lines changed

6 files changed

+233
-168
lines changed

src/db/add_package.rs

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
1-
use std::{
2-
collections::{HashMap, HashSet},
3-
fs,
4-
io::{BufRead, BufReader},
5-
path::Path,
6-
};
7-
81
use crate::{
92
db::types::Feature,
103
docbuilder::{BuildResult, DocCoverage},
114
error::Result,
125
index::api::{CrateData, CrateOwner, ReleaseData},
136
storage::CompressionAlgorithm,
147
utils::MetadataPackage,
8+
web::crate_details::CrateDetails,
159
};
10+
use anyhow::{anyhow, Context};
1611
use log::{debug, info};
1712
use postgres::Client;
1813
use serde_json::Value;
1914
use slug::slugify;
15+
use std::{
16+
collections::{HashMap, HashSet},
17+
fs,
18+
io::{BufRead, BufReader},
19+
path::Path,
20+
};
2021

2122
/// Adds a package into database.
2223
///
@@ -127,12 +128,21 @@ pub(crate) fn add_package_into_database(
127128
add_keywords_into_database(conn, metadata_pkg, release_id)?;
128129
add_compression_into_database(conn, compression_algorithms.into_iter(), release_id)?;
129130

130-
// Update the crates table with the new release
131+
let crate_details = CrateDetails::new(
132+
conn,
133+
&metadata_pkg.name,
134+
&metadata_pkg.version,
135+
&metadata_pkg.version,
136+
None,
137+
)
138+
.context("error when fetching crate-details")?
139+
.ok_or_else(|| anyhow!("crate details not found directly after creating them"))?;
140+
131141
conn.execute(
132142
"UPDATE crates
133143
SET latest_version_id = $2
134144
WHERE id = $1",
135-
&[&crate_id, &release_id],
145+
&[&crate_id, &crate_details.latest_release().id],
136146
)?;
137147

138148
Ok(release_id)

0 commit comments

Comments
 (0)