Remove usages of FIND_IN_SET
FIND_IN_SET doesn't make use of indexes
This commit is contained in:
@ -8,17 +8,6 @@ use std::{
|
||||
hash::{Hash, Hasher},
|
||||
};
|
||||
|
||||
use chrono::{DateTime, NaiveDateTime, Utc};
|
||||
use chrono_tz::Tz;
|
||||
use poise::{
|
||||
serenity_prelude::{
|
||||
model::id::{ChannelId, GuildId, UserId},
|
||||
ButtonStyle, Cache, ChannelType, CreateActionRow, CreateButton, CreateEmbed, ReactionType,
|
||||
},
|
||||
CreateReply,
|
||||
};
|
||||
use sqlx::Executor;
|
||||
|
||||
use crate::{
|
||||
commands::look::{LookFlags, TimeDisplayType},
|
||||
component_models::{ComponentDataModel, UndoReminder},
|
||||
@ -36,8 +25,18 @@ use crate::{
|
||||
utils::{check_guild_subscription, check_subscription},
|
||||
Context, Database, Error,
|
||||
};
|
||||
use chrono::{DateTime, NaiveDateTime, Utc};
|
||||
use chrono_tz::Tz;
|
||||
use poise::{
|
||||
serenity_prelude::{
|
||||
model::id::{ChannelId, GuildId, UserId},
|
||||
ButtonStyle, Cache, ChannelType, CreateActionRow, CreateButton, CreateEmbed, ReactionType,
|
||||
},
|
||||
CreateReply,
|
||||
};
|
||||
use sqlx::{Executor, FromRow};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
#[derive(Debug, Clone, FromRow)]
|
||||
#[allow(dead_code)]
|
||||
pub struct Reminder {
|
||||
pub id: u32,
|
||||
@ -140,7 +139,7 @@ impl Reminder {
|
||||
channel_id: C,
|
||||
flags: &LookFlags,
|
||||
) -> Vec<Self> {
|
||||
let enabled = if flags.show_disabled { "0,1" } else { "1" };
|
||||
let enabled = if flags.show_disabled { "0" } else { "1" };
|
||||
let channel_id = channel_id.into();
|
||||
|
||||
sqlx::query_as_unchecked!(
|
||||
@ -168,7 +167,7 @@ impl Reminder {
|
||||
WHERE
|
||||
`status` = 'pending' AND
|
||||
channels.channel = ? AND
|
||||
FIND_IN_SET(reminders.enabled, ?)
|
||||
reminders.enabled >= ?
|
||||
ORDER BY
|
||||
reminders.utc_time
|
||||
",
|
||||
@ -194,17 +193,16 @@ impl Reminder {
|
||||
.keys()
|
||||
.into_iter()
|
||||
.map(|k| k.get().to_string())
|
||||
.collect::<Vec<String>>()
|
||||
.join(","),
|
||||
.collect::<Vec<String>>(),
|
||||
)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
match channel_query {
|
||||
Some(channel_query) => {
|
||||
sqlx::query_as_unchecked!(
|
||||
Self,
|
||||
Some(channels) => {
|
||||
let placeholder = vec!["?"; channels.len()].join(",");
|
||||
let sql = format!(
|
||||
"
|
||||
SELECT
|
||||
reminders.id,
|
||||
@ -227,12 +225,16 @@ impl Reminder {
|
||||
channels.id = reminders.channel_id
|
||||
WHERE
|
||||
`status` = 'pending' AND
|
||||
FIND_IN_SET(channels.channel, ?)
|
||||
",
|
||||
channel_query
|
||||
)
|
||||
.fetch_all(pool)
|
||||
.await
|
||||
channels.channel IN ({placeholder})
|
||||
"
|
||||
);
|
||||
|
||||
let mut query = sqlx::query_as::<Database, Self>(&sql);
|
||||
for channel in channels {
|
||||
query = query.bind(channel);
|
||||
}
|
||||
|
||||
query.fetch_all(pool).await
|
||||
}
|
||||
None => {
|
||||
sqlx::query_as_unchecked!(
|
||||
|
Reference in New Issue
Block a user