Skip to content

Commit

Permalink
index timestamps
Browse files Browse the repository at this point in the history
  • Loading branch information
facundoolano committed Jun 27, 2024
1 parent 6a9c3a4 commit bc50f26
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 3 deletions.
4 changes: 4 additions & 0 deletions feedi/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ def create_app():
def shutdown_session(exception=None):
models.db.session.remove()

# profile sql at http://localhost:9988/__sqltap__
# import sqltap.wsgi
# app.wsgi_app = sqltap.wsgi.SQLTapMiddleware(app.wsgi_app)

return app


Expand Down
6 changes: 3 additions & 3 deletions feedi/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ class Feed(db.Model):
name = sa.Column(sa.String)
icon_url = sa.Column(sa.String)

created = sa.Column(sa.TIMESTAMP, nullable=False, default=datetime.datetime.utcnow)
created = sa.Column(sa.TIMESTAMP, nullable=False, default=datetime.datetime.utcnow, index=True)
updated = sa.Column(sa.TIMESTAMP, nullable=False,
default=datetime.datetime.utcnow, onupdate=datetime.datetime.utcnow)
last_fetch = sa.Column(sa.TIMESTAMP)
Expand Down Expand Up @@ -454,14 +454,14 @@ class Entry(db.Model):

media_url = sa.Column(sa.String, doc="URL of a media attachement or preview.")

created = sa.Column(sa.TIMESTAMP, nullable=False, default=datetime.datetime.utcnow)
created = sa.Column(sa.TIMESTAMP, nullable=False, default=datetime.datetime.utcnow, index=True)
updated = sa.Column(sa.TIMESTAMP, nullable=False,
default=datetime.datetime.utcnow, onupdate=datetime.datetime.utcnow)
display_date = sa.Column(sa.TIMESTAMP, nullable=False,
doc="The date that will displayed as the publication date of the entry. \
Typically the publication or creation date informed at the source.")

sort_date = sa.Column(sa.TIMESTAMP, nullable=False,
sort_date = sa.Column(sa.TIMESTAMP, nullable=False, index=True,
doc="The date that determines an entry's chronological order. \
Typically the updated date informed at the source.")

Expand Down
36 changes: 36 additions & 0 deletions migrations/versions/c5f1b8431345_added_date_indexes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
"""Added date indexes
Revision ID: c5f1b8431345
Revises: 85eecf551f0e
Create Date: 2024-06-25 21:23:39.365717
"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision: str = 'c5f1b8431345'
down_revision: Union[str, None] = '85eecf551f0e'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('entries', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_entries_created'), ['created'], unique=False)
batch_op.create_index(batch_op.f('ix_entries_sort_date'), ['sort_date'], unique=False)

# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('entries', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_entries_sort_date'))
batch_op.drop_index(batch_op.f('ix_entries_created'))

# ### end Alembic commands ###

0 comments on commit bc50f26

Please sign in to comment.