From 9d557310739c24c3ddcee5ec219332f3d840fdf8 Mon Sep 17 00:00:00 2001 From: Greg Heartsfield Date: Fri, 17 Feb 2023 21:04:30 -0600 Subject: [PATCH] fix: Postgres SQL generation for expiring events --- src/repo/postgres.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/repo/postgres.rs b/src/repo/postgres.rs index be2ec3d..f9b85ca 100644 --- a/src/repo/postgres.rs +++ b/src/repo/postgres.rs @@ -550,6 +550,7 @@ fn query_from_filter(f: &ReqFilter) -> Option> { let mut query = QueryBuilder::new("SELECT e.\"content\", e.created_at FROM \"event\" e WHERE "); + // This tracks whether we need to push a prefix AND before adding another clause let mut push_and = false; // Query for "authors", allowing prefix matches if let Some(auth_vec) = &f.authors { @@ -747,13 +748,9 @@ fn query_from_filter(f: &ReqFilter) -> Option> { } else { query.push("e.hidden != 1::bit(1)"); } - // never display expired events - if push_and { - query.push(" AND "); - } query - .push("(e.expires_at IS NULL OR e.expires_at > ") + .push(" AND (e.expires_at IS NULL OR e.expires_at > ") .push_bind(Utc.timestamp_opt(utils::unix_time() as i64, 0).unwrap()).push(")"); // Apply per-filter limit to this query.