From c31c47d6b10bb0e68f7dc5db7dec7ad9974cc511 Mon Sep 17 00:00:00 2001 From: Deimos Date: Fri, 24 Jul 2020 19:29:20 -0600 Subject: [PATCH] Restrict link topic repost check to last 6 months Previously, when checking if a link had been posted before, there was no restriction on the time limit, so even posts from years ago would come up. This restricts it to only the last 6 months, which I think is a pretty reasonable time period for reposting. --- tildes/tildes/views/topic.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tildes/tildes/views/topic.py b/tildes/tildes/views/topic.py index 2ea6f74..7a4cd10 100644 --- a/tildes/tildes/views/topic.py +++ b/tildes/tildes/views/topic.py @@ -4,6 +4,7 @@ """Views related to posting/viewing topics and comments on them.""" from collections import namedtuple +from datetime import timedelta from difflib import SequenceMatcher from typing import Any, Optional, Union @@ -63,10 +64,13 @@ def post_group_topics( group = request.context if link: - # check to see if this link has been posted before + # check to see if this link has already been posted in the last 6 months previous_topics = ( request.query(Topic) - .filter(Topic.link == link) + .filter( + Topic.link == link, + Topic.created_time >= utc_now() - timedelta(days=180), + ) .order_by(desc(Topic.created_time)) .limit(5) .all()