Compare commits

...

2 Commits

Author SHA1 Message Date
298bae2e78
feat: add shadowbans 2024-07-26 16:16:29 -04:00
f69c73ed66
perf: remove duplicate join 2024-07-26 04:56:42 -04:00
5 changed files with 13 additions and 13 deletions

View File

@ -0,0 +1,2 @@
alter table users
add column shadowbanned boolean not null default false;

View File

@ -0,0 +1 @@
create index messages_territory_id_idx on messages (territory, id);

View File

@ -67,7 +67,7 @@ async fn logic(state: Arc<State>, id: i64, location: u32, query: GetLocationQuer
m.message, m.message,
coalesce(sum(v.vote between 0 and 1), 0) as positive_votes, coalesce(sum(v.vote between 0 and 1), 0) as positive_votes,
coalesce(sum(v.vote between -1 and 0), 0) as negative_votes, coalesce(sum(v.vote between -1 and 0), 0) as negative_votes,
coalesce(v2.vote, 0) as user_vote, coalesce(sum(case when v.user = ? then v.vote else 0 end), 0) as user_vote,
m.glyph, m.glyph,
m.emote as "emote: Json<Option<EmoteData>>", m.emote as "emote: Json<Option<EmoteData>>",
m.created, m.created,
@ -75,10 +75,10 @@ async fn logic(state: Arc<State>, id: i64, location: u32, query: GetLocationQuer
coalesce(cast((julianday(current_timestamp) - julianday(u.last_seen)) * 1440 as int), 0) as last_seen_minutes coalesce(cast((julianday(current_timestamp) - julianday(u.last_seen)) * 1440 as int), 0) as last_seen_minutes
from messages m from messages m
left join votes v on m.id = v.message left join votes v on m.id = v.message
left join votes v2 on m.id = v2.message and v2.user = ?
inner join users u on m.user = u.id inner join users u on m.user = u.id
where m.territory = ? and m.world is ? and m.ward is ? and m.plot is ? where m.territory = ? and not u.shadowbanned and m.world is ? and m.ward is ? and m.plot is ?
group by m.id"#, group by m.id
"#,
id, id,
location, location,
world, world,
@ -103,7 +103,7 @@ async fn logic(state: Arc<State>, id: i64, location: u32, query: GetLocationQuer
m.message, m.message,
coalesce(sum(v.vote between 0 and 1), 0) as positive_votes, coalesce(sum(v.vote between 0 and 1), 0) as positive_votes,
coalesce(sum(v.vote between -1 and 0), 0) as negative_votes, coalesce(sum(v.vote between -1 and 0), 0) as negative_votes,
coalesce(v2.vote, 0) as user_vote, coalesce(sum(case when v.user = ? then v.vote else 0 end), 0) as user_vote,
m.glyph, m.glyph,
m.emote as "emote: Json<Option<EmoteData>>", m.emote as "emote: Json<Option<EmoteData>>",
m.created, m.created,
@ -111,10 +111,10 @@ async fn logic(state: Arc<State>, id: i64, location: u32, query: GetLocationQuer
coalesce(cast((julianday(current_timestamp) - julianday(u.last_seen)) * 1440 as int), 0) as last_seen_minutes coalesce(cast((julianday(current_timestamp) - julianday(u.last_seen)) * 1440 as int), 0) as last_seen_minutes
from messages m from messages m
left join votes v on m.id = v.message left join votes v on m.id = v.message
left join votes v2 on m.id = v2.message and v2.user = ?
inner join users u on m.user = u.id inner join users u on m.user = u.id
where m.territory = ? where m.territory = ? and not u.shadowbanned
group by m.id"#, group by m.id
"#,
id, id,
location, location,
) )
@ -182,7 +182,6 @@ fn filter_messages(messages: &mut Vec<RetrievedMessage>, id: i64, vote_threshold
} }
}; };
let time_since_creation = a.created.signed_duration_since(Utc::now().naive_utc()); let time_since_creation = a.created.signed_duration_since(Utc::now().naive_utc());
let brand_new = time_since_creation < Duration::minutes(30); let brand_new = time_since_creation < Duration::minutes(30);
let new = time_since_creation < Duration::hours(2); let new = time_since_creation < Duration::hours(2);

View File

@ -38,13 +38,12 @@ async fn logic(state: Arc<State>, id: i64, message_id: Uuid) -> Result<impl Repl
m.message, m.message,
coalesce(sum(v.vote between 0 and 1), 0) as positive_votes, coalesce(sum(v.vote between 0 and 1), 0) as positive_votes,
coalesce(sum(v.vote between -1 and 0), 0) as negative_votes, coalesce(sum(v.vote between -1 and 0), 0) as negative_votes,
coalesce(v2.vote, 0) as user_vote, coalesce(sum(case when v.user = ? then v.vote else 0 end), 0) as user_vote,
m.glyph, m.glyph,
m.emote as "emote: Json<Option<EmoteData>>", m.emote as "emote: Json<Option<EmoteData>>",
m.created m.created
from messages m from messages m
left join votes v on m.id = v.message left join votes v on m.id = v.message
left join votes v2 on m.id = v2.message and v2.user = ?
where m.id = ? where m.id = ?
group by m.id"#, group by m.id"#,
id, id,

View File

@ -42,14 +42,13 @@ async fn logic(state: Arc<State>, id: i64, extra: i64, mut query: HashMap<String
m.message, m.message,
coalesce(sum(v.vote between 0 and 1), 0) as positive_votes, coalesce(sum(v.vote between 0 and 1), 0) as positive_votes,
coalesce(sum(v.vote between -1 and 0), 0) as negative_votes, coalesce(sum(v.vote between -1 and 0), 0) as negative_votes,
coalesce(v2.vote, 0) as user_vote, coalesce(sum(case when v.user = ? then v.vote else 0 end), 0) as user_vote,
m.glyph, m.glyph,
m.created, m.created,
m.emote as "emote: Json<Option<EmoteData>>", m.emote as "emote: Json<Option<EmoteData>>",
0 as "is_hidden: bool" 0 as "is_hidden: bool"
from messages m from messages m
left join votes v on m.id = v.message left join votes v on m.id = v.message
left join votes v2 on m.id = v2.message and v2.user = ?
where m.user = ? where m.user = ?
group by m.id"#, group by m.id"#,
id, id,