Browse Source

Shorten topic re-visit "grace period" to 30 sec

merge-requests/100/head
Deimos 5 years ago
parent
commit
06ec67c144
  1. 58
      tildes/alembic/versions/9b7a7b906956_shorten_topic_re_visit_grace_period.py
  2. 2
      tildes/sql/init/triggers/topic_visits/topic_visits.sql

58
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;
"""
)

2
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;

Loading…
Cancel
Save