Skip to content

Remove index sync feature flag #6375

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 5 commits into from
May 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
13 changes: 2 additions & 11 deletions src/admin/delete_crate.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use crate::background_jobs::Job;
use crate::{admin::dialoguer, config, db, models::Crate, schema::crates};
use crate::{admin::dialoguer, db, models::Crate, schema::crates};

use diesel::prelude::*;
use reqwest::blocking::Client;

#[derive(clap::Parser, Debug)]
#[command(
Expand Down Expand Up @@ -31,10 +30,6 @@ pub fn run(opts: Opts) {
fn delete(opts: Opts, conn: &mut PgConnection) {
let krate: Crate = Crate::by_name(&opts.crate_name).first(conn).unwrap();

let config = config::Base::from_environment();
let uploader = config.uploader();
let client = Client::new();

if !opts.yes {
let prompt = format!(
"Are you sure you want to delete {} ({})?",
Expand All @@ -55,9 +50,5 @@ fn delete(opts: Opts, conn: &mut PgConnection) {
panic!("aborting transaction");
}

if dotenv::var("FEATURE_INDEX_SYNC").is_ok() {
Job::enqueue_sync_to_index(&krate.name, conn).unwrap();
} else {
uploader.delete_index(&client, &krate.name).unwrap();
}
Job::enqueue_sync_to_index(&krate.name, conn).unwrap();
}
4 changes: 1 addition & 3 deletions src/admin/delete_version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,5 @@ fn delete(opts: Opts, conn: &mut PgConnection) {
panic!("aborting transaction");
}

if dotenv::var("FEATURE_INDEX_SYNC").is_ok() {
Job::enqueue_sync_to_index(&krate.name, conn).unwrap();
}
Job::enqueue_sync_to_index(&krate.name, conn).unwrap();
}
6 changes: 1 addition & 5 deletions src/admin/yank_version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,5 @@ fn yank(opts: Opts, conn: &mut PgConnection) {
.execute(conn)
.unwrap();

if dotenv::var("FEATURE_INDEX_SYNC").is_ok() {
Job::enqueue_sync_to_index(&krate.name, conn).unwrap();
} else {
Job::sync_yanked(krate.name, v.num).enqueue(conn).unwrap();
}
Job::enqueue_sync_to_index(&krate.name, conn).unwrap();
}
20 changes: 0 additions & 20 deletions src/background_jobs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,13 @@ macro_rules! job_variant_from_value {

jobs! {
pub enum Job {
AddCrate(AddCrateJob),
DailyDbMaintenance,
DumpDb(DumpDbJob),
NormalizeIndex(NormalizeIndexJob),
RenderAndUploadReadme(RenderAndUploadReadmeJob),
SquashIndex,
SyncToGitIndex(SyncToIndexJob),
SyncToSparseIndex(SyncToIndexJob),
SyncYanked(SyncYankedJob),
UpdateCrateIndex(UpdateCrateIndexJob),
UpdateDownloads,
}
}
Expand Down Expand Up @@ -125,10 +122,6 @@ impl Job {
Ok(())
}

pub fn add_crate(krate: cargo_registry_index::Crate) -> Self {
Self::AddCrate(AddCrateJob { krate })
}

pub fn daily_db_maintenance() -> Self {
Self::DailyDbMaintenance
}
Expand Down Expand Up @@ -176,14 +169,6 @@ impl Job {
})
}

pub fn sync_yanked(krate: String, version_num: String) -> Self {
Self::SyncYanked(SyncYankedJob { krate, version_num })
}

pub fn update_crate_index(crate_name: String) -> Self {
Self::UpdateCrateIndex(UpdateCrateIndexJob { crate_name })
}

pub fn update_downloads() -> Self {
Self::UpdateDownloads
}
Expand Down Expand Up @@ -213,12 +198,7 @@ impl Job {
worker::perform_daily_db_maintenance(&mut *fresh_connection(pool)?)
}
Job::DumpDb(args) => worker::perform_dump_db(env, args.database_url, args.target_name),
Job::AddCrate(args) => worker::perform_index_add_crate(env, conn, &args.krate),
Job::SquashIndex => worker::perform_index_squash(env),
Job::UpdateCrateIndex(args) => worker::perform_index_sync_to_http(env, args.crate_name),
Job::SyncYanked(args) => {
worker::perform_index_update_yanked(env, conn, &args.krate, &args.version_num)
}
Job::NormalizeIndex(args) => worker::perform_normalize_index(env, args),
Job::RenderAndUploadReadme(args) => worker::perform_render_and_upload_readme(
conn,
Expand Down
2 changes: 0 additions & 2 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ pub struct Server {
pub version_id_cache_ttl: Duration,
pub cdn_user_agent: String,
pub balance_capacity: BalanceCapacityConfig,
pub feature_index_sync: bool,
}

impl Default for Server {
Expand Down Expand Up @@ -152,7 +151,6 @@ impl Default for Server {
cdn_user_agent: dotenv::var("WEB_CDN_USER_AGENT")
.unwrap_or_else(|_| "Amazon CloudFront".into()),
balance_capacity: BalanceCapacityConfig::from_environment(),
feature_index_sync: dotenv::var("FEATURE_INDEX_SYNC").is_ok(),
}
}
}
Expand Down
95 changes: 19 additions & 76 deletions src/controllers/krate/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@ use flate2::read::GzDecoder;
use hex::ToHex;
use hyper::body::Buf;
use sha2::{Digest, Sha256};
use std::collections::BTreeMap;
use std::io::Read;
use std::ops::Deref;
use std::path::Path;

use crate::controllers::cargo_prelude::*;
use crate::controllers::util::RequestPartsExt;
use crate::models::{
insert_version_owner_action, Category, Crate, DependencyKind, Keyword, NewCrate, NewVersion,
Rights, VersionAction,
insert_version_owner_action, Category, Crate, Keyword, NewCrate, NewVersion, Rights,
VersionAction,
};

use crate::middleware::log_request::RequestLogExt;
Expand Down Expand Up @@ -209,9 +208,9 @@ pub async fn publish(app: AppState, req: BytesRequest) -> AppResult<Json<GoodCra
// to get here, and max upload sizes are way less than i32 max
content_length as i32,
user.id,
hex_cksum.clone(),
links.clone(),
rust_version.clone(),
hex_cksum,
links,
rust_version,
)?
.save(conn, &verified_email_address)?;

Expand All @@ -224,7 +223,7 @@ pub async fn publish(app: AppState, req: BytesRequest) -> AppResult<Json<GoodCra
)?;

// Link this new version to all dependencies
let git_deps = add_dependencies(conn, &new_crate.deps, version.id)?;
add_dependencies(conn, &new_crate.deps, version.id)?;

// Update all keywords for this crate
Keyword::update_crate(conn, &krate, &keywords)?;
Expand Down Expand Up @@ -255,37 +254,7 @@ pub async fn publish(app: AppState, req: BytesRequest) -> AppResult<Json<GoodCra
.uploader()
.upload_crate(app.http_client(), tarball_bytes, &krate, vers)?;

let (features, features2): (BTreeMap<_, _>, BTreeMap<_, _>) =
features.into_iter().partition(|(_k, vals)| {
!vals
.iter()
.any(|v| v.starts_with("dep:") || v.contains("?/"))
});
let (features2, v) = if features2.is_empty() {
(None, None)
} else {
(Some(features2), Some(2))
};

// Register this crate in our local git repo.
let git_crate = cargo_registry_index::Crate {
name: name.0,
vers: vers.to_string(),
cksum: hex_cksum,
features,
features2,
deps: git_deps,
yanked: Some(false),
links,
rust_version,
v,
};

if app.config.feature_index_sync {
Job::enqueue_sync_to_index(&krate.name, conn)?;
} else {
Job::add_crate(git_crate).enqueue(conn)?;
}
Job::enqueue_sync_to_index(&krate.name, conn)?;

// The `other` field on `PublishWarnings` was introduced to handle a temporary warning
// that is no longer needed. As such, crates.io currently does not return any `other`
Expand Down Expand Up @@ -374,11 +343,11 @@ pub fn add_dependencies(
conn: &mut PgConnection,
deps: &[EncodableCrateDependency],
target_version_id: i32,
) -> AppResult<Vec<cargo_registry_index::Dependency>> {
) -> AppResult<()> {
use self::dependencies::dsl::*;
use diesel::insert_into;

let git_and_new_dependencies = deps
let new_dependencies = deps
.iter()
.map(|dep| {
if let Some(registry) = &dep.registry {
Expand All @@ -398,51 +367,25 @@ pub fn add_dependencies(
}
}

// If this dependency has an explicit name in `Cargo.toml` that
// means that the `name` we have listed is actually the package name
// that we're depending on. The `name` listed in the index is the
// Cargo.toml-written-name which is what cargo uses for
// `--extern foo=...`
let (name, package) = match &dep.explicit_name_in_toml {
Some(explicit) => (explicit.to_string(), Some(dep.name.to_string())),
None => (dep.name.to_string(), None),
};

Ok((
cargo_registry_index::Dependency {
name,
req: dep.version_req.to_string(),
features: dep.features.iter().map(|s| s.0.to_string()).collect(),
optional: dep.optional,
default_features: dep.default_features,
target: dep.target.clone(),
kind: dep.kind.or(Some(DependencyKind::Normal)).map(|dk| dk.into()),
package,
},
(
version_id.eq(target_version_id),
crate_id.eq(krate.id),
req.eq(dep.version_req.to_string()),
dep.kind.map(|k| kind.eq(k as i32)),
optional.eq(dep.optional),
default_features.eq(dep.default_features),
features.eq(&dep.features),
target.eq(dep.target.as_deref()),
explicit_name.eq(dep.explicit_name_in_toml.as_deref())
),
version_id.eq(target_version_id),
crate_id.eq(krate.id),
req.eq(dep.version_req.to_string()),
dep.kind.map(|k| kind.eq(k as i32)),
optional.eq(dep.optional),
default_features.eq(dep.default_features),
features.eq(&dep.features),
target.eq(dep.target.as_deref()),
explicit_name.eq(dep.explicit_name_in_toml.as_deref())
))
})
.collect::<Result<Vec<_>, _>>()?;

let (mut git_deps, new_dependencies): (Vec<_>, Vec<_>) =
git_and_new_dependencies.into_iter().unzip();
git_deps.sort();

insert_into(dependencies)
.values(&new_dependencies)
.execute(conn)?;

Ok(git_deps)
Ok(())
}

#[derive(Debug)]
Expand Down
6 changes: 1 addition & 5 deletions src/controllers/version/yank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,7 @@ fn modify_yank(

insert_version_owner_action(conn, version.id, user.id, api_token_id, action)?;

if state.config.feature_index_sync {
Job::enqueue_sync_to_index(&krate.name, conn)?;
} else {
Job::sync_yanked(krate.name, version.num).enqueue(conn)?;
}
Job::enqueue_sync_to_index(&krate.name, conn)?;

ok_true()
}
1 change: 0 additions & 1 deletion src/tests/util/test_app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,6 @@ fn simple_config() -> config::Server {
version_id_cache_ttl: Duration::from_secs(5 * 60),
cdn_user_agent: "Amazon CloudFront".to_string(),
balance_capacity: BalanceCapacityConfig::for_testing(),
feature_index_sync: true,
}
}

Expand Down
Loading