diff --git a/src/db/board_stroke.rs b/src/db/board_stroke.rs index 9277e72..0b10745 100644 --- a/src/db/board_stroke.rs +++ b/src/db/board_stroke.rs @@ -216,8 +216,8 @@ pub async fn clear(db: &Database, board: &BoardId, by: &UserId) -> Result, offset: i64, ) -> Result<(Vec, i64), AppError> { - let scope = match epoch { - Some(_) => " AND epoch = $2", - None => "", + // The builder binds positionally in call order, so each optional clause + // takes the placeholder number its position in the bind sequence gives + // it — epoch (when present) is always $2, the marker filter $3 only + // when the epoch clause is there too. + let (scope, kinds) = match (epoch.is_some(), marks_only) { + (true, true) => (" AND epoch = $2", " AND kind != $3"), + (true, false) => (" AND epoch = $2", ""), + (false, true) => ("", " AND kind != $2"), + (false, false) => ("", ""), }; - let kinds = if marks_only { " AND kind != $3" } else { "" }; let mut list = PagedList::new( format!("board_stroke WHERE board = $1{scope}{kinds}"), "ORDER BY id", ) .bind(board.uuid()); - if epoch.is_some() { - list = list.bind(epoch.unwrap_or_default()); + if let Some(epoch) = epoch { + list = list.bind(epoch); } if marks_only { list = list.bind(KIND_CLEAR.to_string());