add sqlite optimization hints and handle all ignores
This commit is contained in:
parent
07b4679238
commit
bd6466ff5f
1 changed files with 10 additions and 8 deletions
|
@ -72,7 +72,9 @@ async def handle_triggers(ctx, message):
|
|||
"is_bot": ctx.author.bot,
|
||||
}
|
||||
|
||||
disabled = await fetch_exists(ctx.bot.db, "SELECT * FROM users WHERE user_id=:author AND disabled IS 1", params)
|
||||
disabled = await fetch_exists(
|
||||
ctx.bot.db, "SELECT * FROM users WHERE user_id=:author AND unlikely(disabled IS 1)", params
|
||||
)
|
||||
|
||||
if disabled:
|
||||
log.debug(f"User {ctx.author} ({ctx.author.id}) opted out")
|
||||
|
@ -86,17 +88,17 @@ async def handle_triggers(ctx, message):
|
|||
SELECT keyword, user_id, use_embed, row_number() over (partition by user_id) n
|
||||
FROM keywords
|
||||
LEFT JOIN users USING (user_id)
|
||||
WHERE disabled IS NOT 1 -- Don't notify users who opted out
|
||||
AND (notify_self IS 1 OR user_id IS NOT :author) -- Don't notify author unless wanted
|
||||
AND (bots_notify IS 1 OR :is_bot IS NOT 1) -- Don't notify from bots unless wanted
|
||||
AND :author NOT IN ( -- Don't notify if...
|
||||
SELECT target FROM user_ignores -- Author is ignored in this guild
|
||||
WHERE likely(disabled IS NOT 1) -- Don't notify users who opted out
|
||||
AND (unlikely(notify_self IS 1) OR user_id IS NOT :author) -- Don't notify author unless wanted
|
||||
AND (unlikely(bots_notify IS 1) OR :is_bot IS NOT 1) -- Don't notify from bots unless wanted
|
||||
AND likely(NOT EXISTS(SELECT * FROM ( -- Don't notify if...
|
||||
SELECT target FROM user_ignores -- Author or channel is ignored in this guild
|
||||
WHERE user_id=user_id AND guild_id=guild_id
|
||||
UNION
|
||||
SELECT target FROM user_blocks -- Author is blocked
|
||||
WHERE user_id=user_id
|
||||
)
|
||||
AND guild_id=:guild AND contains(:content, keyword, regex)
|
||||
) WHERE target IN (:author, :channel)))
|
||||
AND guild_id=:guild AND unlikely(contains(:content, keyword, regex))
|
||||
)
|
||||
WHERE n=1
|
||||
"""
|
||||
|
|
Loading…
Reference in a new issue