chore: code cleanup (mostly whitespace / remove unused imports)
This commit is contained in:
@@ -5,8 +5,6 @@ using App.Metrics;
|
||||
|
||||
using Dapper;
|
||||
|
||||
using Npgsql;
|
||||
|
||||
using SqlKata;
|
||||
|
||||
namespace PluralKit.Core;
|
||||
@@ -82,8 +80,10 @@ internal partial class Database: IDatabase
|
||||
var query = _compiler.Compile(q);
|
||||
using var conn = await Obtain();
|
||||
using (_metrics.Measure.Timer.Time(CoreMetrics.DatabaseQuery, new MetricTags("Query", queryName)))
|
||||
{
|
||||
await foreach (var val in conn.QueryStreamAsync<T>(query.Sql, query.NamedBindings))
|
||||
yield return val;
|
||||
}
|
||||
}
|
||||
|
||||
// the procedures (message_context and proxy_members, as of writing) have their own metrics tracking elsewhere
|
||||
|
@@ -27,22 +27,22 @@ as $$
|
||||
where accounts.uid = account_id),
|
||||
guild as (select * from servers where id = guild_id)
|
||||
select
|
||||
system.id as system_id,
|
||||
system.id as system_id,
|
||||
system.is_deleting,
|
||||
guild.log_channel,
|
||||
(channel_id = any(guild.blacklist)) as in_blacklist,
|
||||
(channel_id = any(guild.log_blacklist)) as in_log_blacklist,
|
||||
(channel_id = any (guild.blacklist)) as in_blacklist,
|
||||
(channel_id = any (guild.log_blacklist)) as in_log_blacklist,
|
||||
coalesce(guild.log_cleanup_enabled, false),
|
||||
coalesce(system_guild.proxy_enabled, true) as proxy_enabled,
|
||||
system_last_switch.switch as last_switch,
|
||||
system_last_switch.members as last_switch_members,
|
||||
system_last_switch.timestamp as last_switch_timestamp,
|
||||
system.tag as system_tag,
|
||||
system.guild_tag as system_guild_tag,
|
||||
coalesce(system.tag_enabled, true) as tag_enabled,
|
||||
system.avatar_url as system_avatar,
|
||||
system.account_autoproxy as allow_autoproxy,
|
||||
system.latch_timeout as latch_timeout
|
||||
system_last_switch.switch as last_switch,
|
||||
system_last_switch.members as last_switch_members,
|
||||
system_last_switch.timestamp as last_switch_timestamp,
|
||||
system.tag as system_tag,
|
||||
system.guild_tag as system_guild_tag,
|
||||
coalesce(system.tag_enabled, true) as tag_enabled,
|
||||
system.avatar_url as system_avatar,
|
||||
system.account_autoproxy as allow_autoproxy,
|
||||
system.latch_timeout as latch_timeout
|
||||
-- We need a "from" clause, so we just use some bogus data that's always present
|
||||
-- This ensure we always have exactly one row going forward, so we can left join afterwards and still get data
|
||||
from (select 1) as _placeholder
|
||||
@@ -60,7 +60,7 @@ create function proxy_members(account_id bigint, guild_id bigint)
|
||||
id int,
|
||||
proxy_tags proxy_tag[],
|
||||
keep_proxy bool,
|
||||
|
||||
|
||||
server_name text,
|
||||
display_name text,
|
||||
name text,
|
||||
@@ -75,22 +75,22 @@ create function proxy_members(account_id bigint, guild_id bigint)
|
||||
as $$
|
||||
select
|
||||
-- Basic data
|
||||
members.id as id,
|
||||
members.proxy_tags as proxy_tags,
|
||||
members.keep_proxy as keep_proxy,
|
||||
|
||||
members.id as id,
|
||||
members.proxy_tags as proxy_tags,
|
||||
members.keep_proxy as keep_proxy,
|
||||
|
||||
-- Name info
|
||||
member_guild.display_name as server_name,
|
||||
members.display_name as display_name,
|
||||
members.name as name,
|
||||
|
||||
members.display_name as display_name,
|
||||
members.name as name,
|
||||
|
||||
-- Avatar info
|
||||
member_guild.avatar_url as server_avatar,
|
||||
members.avatar_url as avatar,
|
||||
member_guild.avatar_url as server_avatar,
|
||||
members.avatar_url as avatar,
|
||||
|
||||
members.color as color,
|
||||
members.color as color,
|
||||
|
||||
members.allow_autoproxy as allow_autoproxy
|
||||
members.allow_autoproxy as allow_autoproxy
|
||||
from accounts
|
||||
inner join systems on systems.id = accounts.system
|
||||
inner join members on members.system = systems.id
|
||||
|
@@ -1,6 +1,6 @@
|
||||
-- Returns one row per system, containing info about latest switch + array of member IDs (for future joins)
|
||||
create view system_last_switch as
|
||||
select systems.id as system,
|
||||
select systems.id as system,
|
||||
last_switch.id as switch,
|
||||
last_switch.timestamp as timestamp,
|
||||
array(select member from switch_members where switch_members.switch = last_switch.id order by switch_members.id) as members
|
||||
@@ -10,16 +10,16 @@ from systems
|
||||
-- Returns one row for every current fronter in a system, w/ some member info
|
||||
create view system_fronters as
|
||||
select
|
||||
systems.id as system_id,
|
||||
last_switch.id as switch_id,
|
||||
systems.id as system_id,
|
||||
last_switch.id as switch_id,
|
||||
last_switch.timestamp as switch_timestamp,
|
||||
members.id as member_id,
|
||||
members.hid as member_hid,
|
||||
members.name as member_name
|
||||
members.id as member_id,
|
||||
members.hid as member_hid,
|
||||
members.name as member_name
|
||||
from systems
|
||||
-- TODO: is there a more efficient way of doing this search? might need to index on timestamp if we haven't in prod
|
||||
inner join lateral (select * from switches where switches.system = systems.id order by timestamp desc limit 1) as last_switch on true
|
||||
|
||||
|
||||
-- change to left join to handle memberless switches?
|
||||
inner join switch_members on switch_members.switch = last_switch.system
|
||||
inner join members on members.id = switch_members.member
|
||||
@@ -30,8 +30,8 @@ create view member_list as
|
||||
select members.*,
|
||||
-- Find last message ID
|
||||
-- max(mid) does full table scan, order by/limit uses index (dunno why, but it works!)
|
||||
-- (select mid from messages where messages.member = members.id order by mid desc nulls last limit 1) as last_message,
|
||||
|
||||
-- (select mid from messages where messages.member = members.id order by mid desc nulls last limit 1) as last_message,
|
||||
|
||||
-- Find last switch timestamp
|
||||
(
|
||||
select max(switches.timestamp)
|
||||
@@ -39,20 +39,20 @@ select members.*,
|
||||
inner join switches on switches.id = switch_members.switch
|
||||
where switch_members.member = members.id
|
||||
) as last_switch_time,
|
||||
|
||||
|
||||
-- Extract month/day from birthday and "force" the year identical (just using 4) -> month/day only sorting!
|
||||
case when members.birthday is not null then
|
||||
make_date(
|
||||
4,
|
||||
extract(month from members.birthday)::integer,
|
||||
extract(day from members.birthday)::integer
|
||||
) end as birthday_md,
|
||||
case when members.birthday is not null then
|
||||
make_date(
|
||||
4,
|
||||
extract(month from members.birthday)::integer,
|
||||
extract(day from members.birthday)::integer
|
||||
) end as birthday_md,
|
||||
|
||||
-- Extract member description as seen by "the public"
|
||||
case
|
||||
-- Privacy '1' = public; just return description as normal
|
||||
when members.description_privacy = 1 then members.description
|
||||
-- Any other privacy (rn just '2'), return null description (missing case = null in SQL)
|
||||
case
|
||||
-- Privacy '1' = public; just return description as normal
|
||||
when members.description_privacy = 1 then members.description
|
||||
-- Any other privacy (rn just '2'), return null description (missing case = null in SQL)
|
||||
end as public_description
|
||||
from members;
|
||||
|
||||
@@ -60,16 +60,16 @@ create view group_list as
|
||||
select groups.*,
|
||||
-- Find public group member count
|
||||
(
|
||||
select count(*) from group_members
|
||||
inner join members on group_members.member_id = members.id
|
||||
where
|
||||
select count(*) from group_members
|
||||
inner join members on group_members.member_id = members.id
|
||||
where
|
||||
group_members.group_id = groups.id and members.member_visibility = 1
|
||||
) as public_member_count,
|
||||
-- Find private group member count
|
||||
(
|
||||
select count(*) from group_members
|
||||
inner join members on group_members.member_id = members.id
|
||||
where
|
||||
select count(*) from group_members
|
||||
inner join members on group_members.member_id = members.id
|
||||
where
|
||||
group_members.group_id = groups.id
|
||||
) as total_member_count
|
||||
from groups;
|
Reference in New Issue
Block a user