Skip to content

Commit

Permalink
Updated index
Browse files Browse the repository at this point in the history
  • Loading branch information
acasajus committed Jul 28, 2023
1 parent 29d780f commit 5f38cdb
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 8 deletions.
7 changes: 2 additions & 5 deletions app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1472,7 +1472,6 @@ class Alias(Base, ModelMixin):
postgresql_ops={"note": "gin_trgm_ops"},
postgresql_using="gin",
),
Index("ix_alias_created_at", "created_at"),
)

user = orm.relationship(User, foreign_keys=[user_id])
Expand Down Expand Up @@ -3065,7 +3064,7 @@ class Bounce(Base, ModelMixin):
email = sa.Column(sa.String(256), nullable=False, index=True)
info = sa.Column(sa.Text, nullable=True)

__table_args__ = (sa.UniqueConstraint("created_at", name="ix_bounce_created_at"),)
__table_args__ = (sa.Index("ix_bounce_created_at", "created_at"),)


class TransactionalEmail(Base, ModelMixin):
Expand All @@ -3076,9 +3075,7 @@ class TransactionalEmail(Base, ModelMixin):
__tablename__ = "transactional_email"
email = sa.Column(sa.String(256), nullable=False, unique=False)

__table_args__ = (
sa.UniqueConstraint("created_at", name="ix_transactional_email_created_at"),
)
__table_args__ = (sa.Index("ix_transactional_email_created_at", "created_at"),)


class Payout(Base, ModelMixin):
Expand Down
4 changes: 1 addition & 3 deletions cron.py
Original file line number Diff line number Diff line change
Expand Up @@ -671,9 +671,7 @@ def set_custom_domain_for_alias():
def sanitize_alias_address_name():
count = 0
# using Alias.all() will take all the memory
for alias in Alias.filter(
Alias.created_at > arrow.now().shift(days=-7)
).yield_per_query():
for alias in Alias.yield_per_query():
if count % 1000 == 0:
LOG.d("process %s", count)

Expand Down
41 changes: 41 additions & 0 deletions migrations/versions/2023_072819_01827104004b_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
"""empty message
Revision ID: 01827104004b
Revises: 2634b41f54db
Create Date: 2023-07-28 19:39:28.675490
"""
import sqlalchemy_utils
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '01827104004b'
down_revision = '2634b41f54db'
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_index(op.f('ix_alias_hibp_last_check'), 'alias', ['hibp_last_check'], unique=False)
op.create_index('ix_bounce_created_at', 'bounce', ['created_at'], unique=False)
op.create_index('ix_monitoring_created_at', 'monitoring', ['created_at'], unique=False)
op.create_index('ix_transactional_email_created_at', 'transactional_email', ['created_at'], unique=False)
op.create_index(op.f('ix_users_activated'), 'users', ['activated'], unique=False)
op.create_index('ix_users_activated_trial_end_lifetime', 'users', ['activated', 'trial_end', 'lifetime'], unique=False)
op.create_index(op.f('ix_users_referral_id'), 'users', ['referral_id'], unique=False)
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_index(op.f('ix_users_referral_id'), table_name='users')
op.drop_index('ix_users_activated_trial_end_lifetime', table_name='users')
op.drop_index(op.f('ix_users_activated'), table_name='users')
op.drop_index('ix_transactional_email_created_at', table_name='transactional_email')
op.drop_index('ix_monitoring_created_at', table_name='monitoring')
op.drop_index('ix_bounce_created_at', table_name='bounce')
op.drop_index(op.f('ix_alias_hibp_last_check'), table_name='alias')
# ### end Alembic commands ###

0 comments on commit 5f38cdb

Please sign in to comment.