Skip to content

Commit f01452b

Browse files
ilmarireivilibre
authored andcommitted
Avoid emitting empty transactions
When generating SQL with transactions, it was emitting empty transactions when the old and new state map entries were the same. Avoid this by using `filter_map` and returning `None` instead of an empty string.
1 parent 4be148a commit f01452b

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ fn generate_sql<'a>(
424424
new_map: &'a BTreeMap<i64, StateGroupEntry>,
425425
room_id: &'a str,
426426
) -> impl Iterator<Item = String> + 'a {
427-
old_map.iter().map(move |(sg, old_entry)| {
427+
old_map.iter().filter_map(move |(sg, old_entry)| {
428428
let new_entry = &new_map[sg];
429429

430430
// Check if the new map has a different entry for this state group
@@ -480,9 +480,9 @@ fn generate_sql<'a>(
480480
sql.replace_range((sql.len() - 2).., ";\n");
481481
}
482482

483-
sql
483+
Some(sql)
484484
} else {
485-
String::new()
485+
None
486486
}
487487
})
488488
}

0 commit comments

Comments
 (0)