Files
duty-teller/alembic/versions/008_duties_indexes.py
Nikolay Tatarinov 0e8d1453e2
All checks were successful
CI / lint-and-test (push) Successful in 24s
Docker Build and Release / build-and-push (push) Successful in 49s
Docker Build and Release / release (push) Successful in 8s
feat: implement caching for duty-related data and enhance performance
- Added a TTLCache class for in-memory caching of duty-related data, improving performance by reducing database queries.
- Integrated caching into the group duty pin functionality, allowing for efficient retrieval of message text and next shift end times.
- Introduced new methods to invalidate caches when relevant data changes, ensuring data consistency.
- Created a new Alembic migration to add indexes on the duties table for improved query performance.
- Updated tests to cover the new caching behavior and ensure proper functionality.
2026-02-25 13:25:34 +03:00

45 lines
1.1 KiB
Python

"""Add indexes on duties table for performance.
Revision ID: 008
Revises: 007
Create Date: 2025-02-25
Indexes for get_current_duty, get_next_shift_end, get_duties, get_duties_for_user.
"""
from typing import Sequence, Union
from alembic import op
revision: str = "008"
down_revision: Union[str, None] = "007"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
op.create_index(
"ix_duties_event_type_start_at",
"duties",
["event_type", "start_at"],
unique=False,
)
op.create_index(
"ix_duties_event_type_end_at",
"duties",
["event_type", "end_at"],
unique=False,
)
op.create_index(
"ix_duties_user_id_start_at",
"duties",
["user_id", "start_at"],
unique=False,
)
def downgrade() -> None:
op.drop_index("ix_duties_user_id_start_at", table_name="duties")
op.drop_index("ix_duties_event_type_end_at", table_name="duties")
op.drop_index("ix_duties_event_type_start_at", table_name="duties")