diff --git a/feedi/app.py b/feedi/app.py index 7d66704..70f663f 100644 --- a/feedi/app.py +++ b/feedi/app.py @@ -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 diff --git a/feedi/models.py b/feedi/models.py index e2a4152..4a1dcf6 100644 --- a/feedi/models.py +++ b/feedi/models.py @@ -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) @@ -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.") diff --git a/migrations/versions/c5f1b8431345_added_date_indexes.py b/migrations/versions/c5f1b8431345_added_date_indexes.py new file mode 100644 index 0000000..06e91eb --- /dev/null +++ b/migrations/versions/c5f1b8431345_added_date_indexes.py @@ -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 ###