Speed up delete query

This commit is contained in:
jude 2024-10-04 20:19:06 +01:00
parent 7395685e0d
commit dcfb5a2d4f
2 changed files with 16 additions and 11 deletions

View File

@ -1,6 +1,12 @@
version: '3.3'
services:
bot:
build: ./Containerfile.run
image: reminder-rs-run
restart: always
expose:
- '80'
database:
image: mysql:8.0
restart: always
@ -13,4 +19,3 @@ services:
- '3306'
volumes:
- reminders:/var/lib/mysql

View File

@ -153,17 +153,17 @@ impl ComponentDataModel {
ComponentDataModel::DelSelector(selector) => {
if let ComponentInteractionDataKind::StringSelect { values } = &component.data.kind
{
let selected_id = values.join(",");
let placeholder = values.iter().map(|_| "?").collect::<Vec<&str>>().join(",");
let sql = format!(
"UPDATE reminders SET `status` = 'deleted' WHERE id IN ({placeholder})"
);
let mut query = sqlx::query(&sql);
sqlx::query!(
"
UPDATE reminders SET `status` = 'deleted' WHERE FIND_IN_SET(id, ?)
",
selected_id
)
.execute(&data.database)
.await
.unwrap();
for id in values {
query = query.bind(id);
}
query.execute(&data.database).await.unwrap();
let reminders = Reminder::from_guild(
&ctx,