Skip to content

Commit e0f31b3

Browse files
committed
background_jobs: Remove unused SyncYanked job
This has been replaced by the two `SyncToGit/SparseIndex` jobs
1 parent 1d407bd commit e0f31b3

File tree

3 files changed

+1
-70
lines changed

3 files changed

+1
-70
lines changed

src/background_jobs.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ jobs! {
7878
SquashIndex,
7979
SyncToGitIndex(SyncToIndexJob),
8080
SyncToSparseIndex(SyncToIndexJob),
81-
SyncYanked(SyncYankedJob),
8281
UpdateCrateIndex(UpdateCrateIndexJob),
8382
UpdateDownloads,
8483
}
@@ -176,10 +175,6 @@ impl Job {
176175
})
177176
}
178177

179-
pub fn sync_yanked(krate: String, version_num: String) -> Self {
180-
Self::SyncYanked(SyncYankedJob { krate, version_num })
181-
}
182-
183178
pub fn update_crate_index(crate_name: String) -> Self {
184179
Self::UpdateCrateIndex(UpdateCrateIndexJob { crate_name })
185180
}
@@ -216,9 +211,6 @@ impl Job {
216211
Job::AddCrate(args) => worker::perform_index_add_crate(env, conn, &args.krate),
217212
Job::SquashIndex => worker::perform_index_squash(env),
218213
Job::UpdateCrateIndex(args) => worker::perform_index_sync_to_http(env, args.crate_name),
219-
Job::SyncYanked(args) => {
220-
worker::perform_index_update_yanked(env, conn, &args.krate, &args.version_num)
221-
}
222214
Job::NormalizeIndex(args) => worker::perform_normalize_index(env, args),
223215
Job::RenderAndUploadReadme(args) => worker::perform_render_and_upload_readme(
224216
conn,

src/worker/git.rs

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use crate::background_jobs::{Environment, Job, NormalizeIndexJob};
22
use crate::models;
3-
use crate::schema;
43
use crate::swirl::PerformError;
54
use anyhow::Context;
65
use cargo_registry_index::{Crate, Repository};
@@ -157,66 +156,6 @@ pub fn get_index_data(name: &str, conn: &mut PgConnection) -> anyhow::Result<Opt
157156
Ok(Some(str))
158157
}
159158

160-
/// Yanks or unyanks a crate version. This requires finding the index
161-
/// file, deserlialise the crate from JSON, change the yank boolean to
162-
/// `true` or `false`, write all the lines back out, and commit and
163-
/// push the changes.
164-
#[instrument(skip(env, conn))]
165-
pub fn perform_index_update_yanked(
166-
env: &Environment,
167-
conn: &mut PgConnection,
168-
krate: &str,
169-
version_num: &str,
170-
) -> Result<(), PerformError> {
171-
info!("Syncing yanked status from database into the index");
172-
173-
debug!("Loading yanked status from database");
174-
175-
let yanked: bool = schema::versions::table
176-
.inner_join(schema::crates::table)
177-
.filter(schema::crates::name.eq(&krate))
178-
.filter(schema::versions::num.eq(&version_num))
179-
.select(schema::versions::yanked)
180-
.get_result(conn)
181-
.context("Failed to load yanked status from database")?;
182-
183-
debug!(yanked);
184-
185-
let repo = env.lock_index()?;
186-
let dst = repo.index_file(krate);
187-
188-
let prev = fs::read_to_string(&dst)?;
189-
let new = prev
190-
.lines()
191-
.map(|line| {
192-
let mut git_crate = serde_json::from_str::<Crate>(line)
193-
.map_err(|_| format!("couldn't decode: `{line}`"))?;
194-
if git_crate.name != krate || git_crate.vers != version_num {
195-
return Ok(line.to_string());
196-
}
197-
git_crate.yanked = Some(yanked);
198-
Ok(serde_json::to_string(&git_crate)?)
199-
})
200-
.collect::<Result<Vec<_>, PerformError>>();
201-
let new = new?.join("\n") + "\n";
202-
203-
if new != prev {
204-
fs::write(&dst, new.as_bytes())?;
205-
206-
let action = if yanked { "Yank" } else { "Unyank" };
207-
let message = format!("{action} crate `{krate}#{version_num}`");
208-
209-
repo.commit_and_push(&message, &dst)?;
210-
} else {
211-
debug!("Skipping `yanked` update because index is up-to-date");
212-
}
213-
214-
// Queue another background job to update the http-based index as well.
215-
Job::update_crate_index(krate.to_string()).enqueue(conn)?;
216-
217-
Ok(())
218-
}
219-
220159
/// Collapse the index into a single commit, archiving the current history in a snapshot branch.
221160
#[instrument(skip(env))]
222161
pub fn perform_index_squash(env: &Environment) -> Result<(), PerformError> {

src/worker/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub(crate) use daily_db_maintenance::perform_daily_db_maintenance;
1414
pub(crate) use dump_db::perform_dump_db;
1515
pub(crate) use git::{
1616
perform_index_add_crate, perform_index_squash, perform_index_sync_to_http,
17-
perform_index_update_yanked, perform_normalize_index, sync_to_git_index, sync_to_sparse_index,
17+
perform_normalize_index, sync_to_git_index, sync_to_sparse_index,
1818
};
1919
pub(crate) use readmes::perform_render_and_upload_readme;
2020
pub(crate) use update_downloads::perform_update_downloads;

0 commit comments

Comments
 (0)