-
-
Notifications
You must be signed in to change notification settings - Fork 123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Exclude posts in own subs from spam detection #1946
base: master
Are you sure you want to change the base?
Changes from all commits
6d05682
af4470a
8250c2f
9bb516f
991c6bc
7eaae87
5b6cddf
cdbd615
55e7a0a
9411bf5
d5ab608
84eac60
52d6b92
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,7 +71,7 @@ export default forwardRef(function Reply ({ | |
// no lag for itemRepetition | ||
if (!item.mine && me) { | ||
cache.updateQuery({ | ||
query: gql`{ itemRepetition(parentId: "${parentId}") }` | ||
query: gql`{ itemRepetition(parentId: "${parentId}", sub: "${sub?.name}") }` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See other comment There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I left this as-is, assuming that was a hint how to solve the other comment. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I meant that you have the same issue There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
}, data => { | ||
return { | ||
itemRepetition: (data?.itemRepetition || 0) + 1 | ||
|
@@ -162,7 +162,7 @@ export default forwardRef(function Reply ({ | |
<div className={styles.reply}> | ||
<FeeButtonProvider | ||
baseLineItems={postCommentBaseLineItems({ baseCost: sub?.replyCost ?? 1, comment: true, me: !!me })} | ||
useRemoteLineItems={postCommentUseRemoteLineItems({ parentId: item.id, me: !!me })} | ||
useRemoteLineItems={postCommentUseRemoteLineItems({ parentId: item.id, sub: sub?.name, me: !!me })} | ||
> | ||
<Form | ||
initial={{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
-- exclude posts in own subs from spam detection | ||
CREATE OR REPLACE FUNCTION item_spam(parent_id INTEGER, user_id INTEGER, within INTERVAL, sub_name TEXT) | ||
RETURNS INTEGER | ||
LANGUAGE plpgsql | ||
AS $$ | ||
DECLARE | ||
repeats INTEGER; | ||
self_replies INTEGER; | ||
BEGIN | ||
-- no fee escalation | ||
IF within = interval '0' THEN | ||
RETURN 0; | ||
END IF; | ||
|
||
IF sub_name IS NOT NULL AND user_id = (SELECT "Sub"."userId" FROM "Sub" WHERE "Sub"."name" = sub_name) THEN | ||
RETURN 0; | ||
END IF; | ||
|
||
SELECT count(*) INTO repeats | ||
FROM "Item" | ||
LEFT JOIN "Sub" ON "Sub"."name" = "Item"."subName" | ||
WHERE ( | ||
(parent_id IS NULL AND "parentId" IS NULL) | ||
OR | ||
("parentId" = parent_id AND user_id <> (SELECT i."userId" FROM "Item" i WHERE i.id = "Item"."rootId")) | ||
) | ||
AND "Item"."userId" = user_id | ||
AND "bio" = 'f' | ||
AND ("Sub"."name" IS NULL OR "Sub"."userId" <> user_id) | ||
AND "Item".created_at > now_utc() - within; | ||
|
||
IF parent_id IS NULL THEN | ||
RETURN repeats; | ||
END IF; | ||
|
||
WITH RECURSIVE base AS ( | ||
SELECT "Item".id, "Item"."parentId", "Item"."userId" | ||
FROM "Item" | ||
WHERE id = parent_id | ||
AND "userId" = user_id | ||
AND created_at > now_utc() - within | ||
AND user_id <> (SELECT i."userId" FROM "Item" i WHERE i.id = "Item"."rootId") | ||
UNION ALL | ||
SELECT "Item".id, "Item"."parentId", "Item"."userId" | ||
FROM base p | ||
JOIN "Item" ON "Item".id = p."parentId" AND "Item"."userId" = p."userId" AND "Item".created_at > now_utc() - within) | ||
SELECT count(*) INTO self_replies FROM base; | ||
|
||
RETURN repeats + self_replies; | ||
END; | ||
$$; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As mentioned in the other comment, this should use GraphQL variables.