|
1 |
| -use std::{ |
2 |
| - collections::{HashMap, HashSet}, |
3 |
| - fs, |
4 |
| - io::{BufRead, BufReader}, |
5 |
| - path::Path, |
6 |
| -}; |
7 |
| - |
8 | 1 | use crate::{
|
9 | 2 | db::types::Feature,
|
10 | 3 | docbuilder::{BuildResult, DocCoverage},
|
11 | 4 | error::Result,
|
12 | 5 | index::api::{CrateData, CrateOwner, ReleaseData},
|
13 | 6 | storage::CompressionAlgorithm,
|
14 | 7 | utils::MetadataPackage,
|
| 8 | + web::crate_details::CrateDetails, |
15 | 9 | };
|
| 10 | +use anyhow::{anyhow, Context}; |
16 | 11 | use log::{debug, info};
|
17 | 12 | use postgres::Client;
|
18 | 13 | use serde_json::Value;
|
19 | 14 | use slug::slugify;
|
| 15 | +use std::{ |
| 16 | + collections::{HashMap, HashSet}, |
| 17 | + fs, |
| 18 | + io::{BufRead, BufReader}, |
| 19 | + path::Path, |
| 20 | +}; |
20 | 21 |
|
21 | 22 | /// Adds a package into database.
|
22 | 23 | ///
|
@@ -127,12 +128,15 @@ pub(crate) fn add_package_into_database(
|
127 | 128 | add_keywords_into_database(conn, metadata_pkg, release_id)?;
|
128 | 129 | add_compression_into_database(conn, compression_algorithms.into_iter(), release_id)?;
|
129 | 130 |
|
130 |
| - // Update the crates table with the new release |
| 131 | + let crate_details = CrateDetails::new(conn, &metadata_pkg.name, &metadata_pkg.version, None) |
| 132 | + .with_context(|| anyhow!("error when fetching crate-details"))? |
| 133 | + .ok_or_else(|| anyhow!("crate details not found directly after creating them"))?; |
| 134 | + |
131 | 135 | conn.execute(
|
132 | 136 | "UPDATE crates
|
133 | 137 | SET latest_version_id = $2
|
134 | 138 | WHERE id = $1",
|
135 |
| - &[&crate_id, &release_id], |
| 139 | + &[&crate_id, &crate_details.latest_release().id], |
136 | 140 | )?;
|
137 | 141 |
|
138 | 142 | Ok(release_id)
|
|
0 commit comments