|
1 | | -use crate::models; |
| 1 | +use crate::index::get_index_data; |
2 | 2 | use crate::tasks::spawn_blocking; |
3 | | -use crate::util::diesel::Conn; |
4 | 3 | use crate::worker::Environment; |
5 | 4 | use anyhow::Context; |
6 | 5 | use crates_io_index::Repository; |
7 | 6 | use crates_io_worker::BackgroundJob; |
8 | | -use diesel::{OptionalExtension, RunQueryDsl}; |
9 | 7 | use diesel_async::async_connection_wrapper::AsyncConnectionWrapper; |
10 | | -use sentry::Level; |
11 | 8 | use std::fs; |
12 | 9 | use std::fs::File; |
13 | 10 | use std::io::{ErrorKind, Write}; |
@@ -126,39 +123,3 @@ impl BackgroundJob for SyncToSparseIndex { |
126 | 123 | Ok(()) |
127 | 124 | } |
128 | 125 | } |
129 | | - |
130 | | -#[instrument(skip_all, fields(krate.name = ?name))] |
131 | | -fn get_index_data(name: &str, conn: &mut impl Conn) -> anyhow::Result<Option<String>> { |
132 | | - debug!("Looking up crate by name"); |
133 | | - let Some(krate): Option<models::Crate> = |
134 | | - models::Crate::by_exact_name(name).first(conn).optional()? |
135 | | - else { |
136 | | - return Ok(None); |
137 | | - }; |
138 | | - |
139 | | - debug!("Gathering remaining index data"); |
140 | | - let crates = krate |
141 | | - .index_metadata(conn) |
142 | | - .context("Failed to gather index metadata")?; |
143 | | - |
144 | | - // This can sometimes happen when we delete versions upon owner request |
145 | | - // but don't realize that the crate is now left with no versions at all. |
146 | | - // |
147 | | - // In this case we will delete the crate from the index and log a warning to |
148 | | - // Sentry to clean this up in the database. |
149 | | - if crates.is_empty() { |
150 | | - let message = format!("Crate `{name}` has no versions left"); |
151 | | - sentry::capture_message(&message, Level::Warning); |
152 | | - |
153 | | - return Ok(None); |
154 | | - } |
155 | | - |
156 | | - debug!("Serializing index data"); |
157 | | - let mut bytes = Vec::new(); |
158 | | - crates_io_index::write_crates(&crates, &mut bytes) |
159 | | - .context("Failed to serialize index metadata")?; |
160 | | - |
161 | | - let str = String::from_utf8(bytes).context("Failed to decode index metadata as utf8")?; |
162 | | - |
163 | | - Ok(Some(str)) |
164 | | -} |
0 commit comments