Skip to content

Commit 790f50a

Browse files
committed
always exclude self votes from given vote analytics
1 parent 2654e50 commit 790f50a

File tree

3 files changed

+5
-16
lines changed

3 files changed

+5
-16
lines changed

crates/api/src/vote_analytics/given_by_person.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ pub async fn get_vote_analytics_given_by_person(
3636
let view = VoteAnalyticsGivenByPersonView::read(
3737
&mut context.pool(),
3838
data.person_id,
39-
data.exclude_votes_on_self.unwrap_or_default(),
4039
since,
4140
until,
4241
data.limit,

crates/api_common/src/person.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,6 @@ pub struct ListMediaResponse {
447447
#[cfg_attr(feature = "full", ts(export))]
448448
pub struct GetVoteAnalyticsByPerson {
449449
pub person_id: PersonId,
450-
pub exclude_votes_on_self: Option<bool>,
451450
pub start_time: Option<i64>,
452451
pub end_time: Option<i64>,
453452
pub limit: Option<i64>,

crates/db_views_actor/src/vote_analytics_given_by_view.rs

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ impl VoteAnalyticsGivenByPersonView {
115115
pub async fn read(
116116
pool: &mut DbPool<'_>,
117117
person_id: PersonId,
118-
exclude_votes_on_self: bool,
119118
start_time: Option<DateTime<Utc>>,
120119
end_time: Option<DateTime<Utc>>,
121120
limit: Option<i64>,
@@ -132,11 +131,6 @@ impl VoteAnalyticsGivenByPersonView {
132131

133132
let limit = fetch_limit(limit)?;
134133

135-
let sql_exclude_own = match exclude_votes_on_self {
136-
true => "AND creator.id != voter.id",
137-
false => "",
138-
};
139-
140134
// This is a rather dangerous workaround; this number must be one above than the highest
141135
// parameter used in the statements below without leaving any space. It could probably be
142136
// improved by implementing QueryFragments.
@@ -175,7 +169,7 @@ WITH post_likes_by_voter AS (
175169
JOIN community ON community.id = post.community_id
176170
WHERE voter.id = $1
177171
AND post_like.score != 0
178-
{exclude_own}
172+
AND creator.id != voter.id
179173
{since}
180174
{until}
181175
), post_likes_by_recipient AS (
@@ -219,7 +213,6 @@ SELECT * FROM post_likes_by_recipient
219213
UNION ALL
220214
SELECT * FROM post_likes_by_community
221215
"#,
222-
exclude_own = sql_exclude_own,
223216
since = sql_since_post,
224217
until = sql_until_post,
225218
)).into_boxed()
@@ -249,7 +242,7 @@ WITH comment_likes_by_voter AS (
249242
JOIN community ON community.id = post.community_id
250243
WHERE voter.id = $1
251244
AND comment_like.score != 0
252-
{exclude_own}
245+
AND creator.id != voter.id
253246
{since}
254247
{until}
255248
), comment_likes_by_recipient AS (
@@ -293,7 +286,6 @@ SELECT * FROM comment_likes_by_recipient
293286
UNION ALL
294287
SELECT * FROM comment_likes_by_community
295288
"#,
296-
exclude_own = sql_exclude_own,
297289
since = sql_since_comment,
298290
until = sql_until_comment,
299291
)).into_boxed()
@@ -488,23 +480,22 @@ mod test {
488480
// Test for non-existing person
489481
let invalid_person_id = PersonId(-1);
490482
let view =
491-
VoteAnalyticsGivenByPersonView::read(pool, invalid_person_id, false, None, None, None).await;
483+
VoteAnalyticsGivenByPersonView::read(pool, invalid_person_id, None, None, None).await;
492484
assert!(
493485
view.is_err_and(|e| e == Error::NotFound),
494486
"query should not match a person",
495487
);
496488

497489
// alice exists but hasn't voted on anything
498-
let view =
499-
VoteAnalyticsGivenByPersonView::read(pool, alice.id, false, None, None, None).await?;
490+
let view = VoteAnalyticsGivenByPersonView::read(pool, alice.id, None, None, None).await?;
500491
assert_eq!(0, view.post_votes_total_votes);
501492
assert_eq!(0, view.post_votes_total_upvotes);
502493
assert_eq!(0, view.post_votes_total_downvotes);
503494
assert_eq!(0.0, view.post_votes_total_upvote_percentage);
504495
assert_length!(0, view.post_votes_by_target_user);
505496
assert_length!(0, view.post_votes_by_target_community);
506497

507-
let view = VoteAnalyticsGivenByPersonView::read(pool, bob.id, true, None, None, None).await?;
498+
let view = VoteAnalyticsGivenByPersonView::read(pool, bob.id, None, None, None).await?;
508499

509500
assert_eq!(8, view.post_votes_total_votes);
510501
assert_eq!(3, view.post_votes_total_upvotes);

0 commit comments

Comments
 (0)