diff --git a/tildes/alembic/versions/9b7a7b906956_shorten_topic_re_visit_grace_period.py b/tildes/alembic/versions/9b7a7b906956_shorten_topic_re_visit_grace_period.py new file mode 100644 index 0000000..abf70d8 --- /dev/null +++ b/tildes/alembic/versions/9b7a7b906956_shorten_topic_re_visit_grace_period.py @@ -0,0 +1,58 @@ +"""Shorten topic re-visit grace period + +Revision ID: 9b7a7b906956 +Revises: 4241b0202fd4 +Create Date: 2020-02-07 18:45:43.867078 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = "9b7a7b906956" +down_revision = "4241b0202fd4" +branch_labels = None +depends_on = None + + +def upgrade(): + op.execute( + """ + create or replace function prevent_recent_repeat_visits() returns trigger as $$ + begin + perform * from topic_visits + where user_id = NEW.user_id + and topic_id = NEW.topic_id + and visit_time >= now() - interval '30 seconds'; + + if (FOUND) then + return null; + else + return NEW; + end if; + end; + $$ language plpgsql; + """ + ) + + +def downgrade(): + op.execute( + """ + create or replace function prevent_recent_repeat_visits() returns trigger as $$ + begin + perform * from topic_visits + where user_id = NEW.user_id + and topic_id = NEW.topic_id + and visit_time >= now() - interval '2 minutes'; + + if (FOUND) then + return null; + else + return NEW; + end if; + end; + $$ language plpgsql; + """ + ) diff --git a/tildes/sql/init/triggers/topic_visits/topic_visits.sql b/tildes/sql/init/triggers/topic_visits/topic_visits.sql index 98a4092..efcdf22 100644 --- a/tildes/sql/init/triggers/topic_visits/topic_visits.sql +++ b/tildes/sql/init/triggers/topic_visits/topic_visits.sql @@ -7,7 +7,7 @@ begin perform * from topic_visits where user_id = NEW.user_id and topic_id = NEW.topic_id - and visit_time >= now() - interval '2 minutes'; + and visit_time >= now() - interval '30 seconds'; if (FOUND) then return null;