From 576b23bca573975562264143ff9fc6931683ce16 Mon Sep 17 00:00:00 2001 From: rladenson <78043712+rladenson@users.noreply.github.com> Date: Wed, 6 Apr 2022 00:19:35 -0600 Subject: [PATCH] fix: try getting own-system members first even when matching hid (#439) this is a bandaid fix for an issue where queries matching only the hid index would get stuck forever --- .../Context/ContextEntityArgumentsExt.cs | 30 +++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/PluralKit.Bot/CommandSystem/Context/ContextEntityArgumentsExt.cs b/PluralKit.Bot/CommandSystem/Context/ContextEntityArgumentsExt.cs index 521c0fd6..6088b8a8 100644 --- a/PluralKit.Bot/CommandSystem/Context/ContextEntityArgumentsExt.cs +++ b/PluralKit.Bot/CommandSystem/Context/ContextEntityArgumentsExt.cs @@ -80,8 +80,34 @@ public static class ContextEntityArgumentsExt } // Finally (or if by-HID lookup is specified), try member HID parsing: - if (await ctx.Repository.GetMemberByHid(input, restrictToSystem) is PKMember memberByHid) - return memberByHid; + + // For posterity: + // There was a bug that made `SELECT * FROM MEMBERS WHERE HID = $1` hang forever BUT + // `SELECT * FROM MEMBERS WHERE HID = $1 AND SYSTEM = $2` *doesn't* hang! So this is a bandaid for that + + // If we are supposed to restrict it to a system anyway we can just do that + PKMember memberByHid = null; + if (restrictToSystem != null) + { + memberByHid = await ctx.Repository.GetMemberByHid(input, restrictToSystem); + if (memberByHid != null) + return memberByHid; + } + // otherwise we try the querier's system and if that doesn't work we do global + else + { + memberByHid = await ctx.Repository.GetMemberByHid(input, ctx.System?.Id); + if (memberByHid != null) + return memberByHid; + + // ff ctx.System was null then this would be a duplicate of above and we don't want to run it again + if (ctx.System != null) + { + memberByHid = await ctx.Repository.GetMemberByHid(input); + if (memberByHid != null) + return memberByHid; + } + } // We didn't find anything, so we return null. return null;