From 5aef9e76afa608afe34429f9bbe9b4c50b4b0857 Mon Sep 17 00:00:00 2001 From: Justin Geibel Date: Sat, 15 Feb 2020 11:05:18 -0500 Subject: [PATCH] Revert #2157 It appears that the additional wrapper transaction added around the update_downloads task causes delays and timeouts to download requests whenever the background job is run. Reverting so that master can be deployed. Revert "Auto merge of #2157 - jtgeibel:add-lock-to-update-downloads-job, r=sgrif" This reverts commit c07223bd252413740eff4ef205f88afdea1ce005, reversing changes made to c6d13eba5b35cbc585e84f5ee744c03ecf51f995. --- src/tasks.rs | 5 ----- src/tasks/update_downloads.rs | 14 ++------------ 2 files changed, 2 insertions(+), 17 deletions(-) diff --git a/src/tasks.rs b/src/tasks.rs index 0f33ca99a81..ed9e0e91449 100644 --- a/src/tasks.rs +++ b/src/tasks.rs @@ -3,8 +3,3 @@ mod update_downloads; pub use dump_db::dump_db; pub use update_downloads::update_downloads; - -use diesel::sql_types::BigInt; -sql_function!(fn pg_try_advisory_xact_lock(key: BigInt) -> Bool); - -const UPDATE_DOWNLOADS_ADVISORY_LOCK_KEY: i64 = 1; diff --git a/src/tasks/update_downloads.rs b/src/tasks/update_downloads.rs index 4a8d80f984b..fc1620d6e36 100644 --- a/src/tasks/update_downloads.rs +++ b/src/tasks/update_downloads.rs @@ -1,5 +1,3 @@ -use super::pg_try_advisory_xact_lock; -use super::UPDATE_DOWNLOADS_ADVISORY_LOCK_KEY as LOCK_KEY; use crate::{ background_jobs::Environment, models::VersionDownload, @@ -11,17 +9,9 @@ use swirl::PerformError; #[swirl::background_job] pub fn update_downloads(env: &Environment) -> Result<(), PerformError> { - use diesel::select; - let conn = env.connection()?; - conn.transaction::<_, PerformError, _>(|| { - // If this job runs concurrently with itself, it could result in a overcount - if !select(pg_try_advisory_xact_lock(LOCK_KEY)).get_result(&*conn)? { - return Err("The advisory lock for update_downloads is already taken".into()); - } - - update(&conn).map_err(Into::into) - }) + update(&conn)?; + Ok(()) } fn update(conn: &PgConnection) -> QueryResult<()> {