Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mhm/src-tauri/src/commands/groups.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ pub async fn auto_assign_rooms(
}

let mut floors_sorted: Vec<(i32, Vec<&Room>)> = floor_groups.into_iter().collect();
floors_sorted.sort_by(|a, b| b.1.len().cmp(&a.1.len()));
floors_sorted.sort_by_key(|b| std::cmp::Reverse(b.1.len()));

let mut assignments = Vec::new();
let needed = req.room_count as usize;
Expand Down
24 changes: 18 additions & 6 deletions mhm/src-tauri/src/services/booking/guest_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,24 @@ pub async fn link_booking_guests(
booking_id: &str,
guest_ids: &[String],
) -> BookingResult<()> {
for guest_id in guest_ids {
sqlx::query("INSERT INTO booking_guests (booking_id, guest_id) VALUES (?, ?)")
.bind(booking_id)
.bind(guest_id)
.execute(&mut **tx)
.await?;
if guest_ids.is_empty() {
return Ok(());
}

// Default max variables in modern sqlite is 32766.
// Each insert takes 2 variables, so we can insert at most 16383 rows at once.
// Given the hotel size, we should never reach this. But batching into chunks makes it safe.
let chunks = guest_ids.chunks(16000);

for chunk in chunks {
let mut query_builder =
sqlx::QueryBuilder::new("INSERT INTO booking_guests (booking_id, guest_id) ");

query_builder.push_values(chunk, |mut b, guest_id| {
b.push_bind(booking_id).push_bind(guest_id);
});

query_builder.build().execute(&mut **tx).await?;
}

Ok(())
Expand Down
Loading