Skip to content

Commit

Permalink
made sure that delete_events does not spam the log by blocking too …
Browse files Browse the repository at this point in the history
…long
  • Loading branch information
CommanderStorm committed Jul 15, 2024
1 parent a68d5b5 commit 19dcac4
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 18 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

22 changes: 18 additions & 4 deletions server/main-api/src/calendar/connectum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,24 @@ impl APIRequestor {
&self,
tx: &mut sqlx::Transaction<'_, sqlx::Postgres>,
id: &str,
) -> Result<sqlx::postgres::PgQueryResult, sqlx::Error> {
sqlx::query!(r#"DELETE FROM calendar WHERE room_code = $1"#, id)
.execute(&mut **tx)
.await
) -> Result<(), sqlx::Error> {
loop {
// deliberately somewhat low to not have too long blocking segments
let res = sqlx::query!(r#"
WITH rows_to_delete AS (
SELECT id
FROM calendar WHERE room_code = $1
LIMIT 1000
)
DELETE FROM calendar
WHERE id IN (SELECT id FROM rows_to_delete);"#, id)
.execute(&mut **tx)
.await?;
if res.rows_affected() == 0 {
return Ok(());
}
}
}
#[tracing::instrument(skip(tx))]
async fn update_last_calendar_scrape_at(
Expand Down
1 change: 1 addition & 0 deletions server/main-api/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ pub struct AppData {
impl AppData {
async fn new() -> Self {
let pool = PgPoolOptions::new()
.min_connections(2)
.connect(&connection_string())
.await
.expect("make sure that postgis is running in the background");
Expand Down

0 comments on commit 19dcac4

Please sign in to comment.