diff --git a/src/app/alembic/versions/9b7cfb422191_.py b/src/app/alembic/versions/9b7cfb422191_.py index 8a83629..3983a1a 100644 --- a/src/app/alembic/versions/9b7cfb422191_.py +++ b/src/app/alembic/versions/9b7cfb422191_.py @@ -29,10 +29,21 @@ def upgrade(): "object_id", "object_type", name="uc_cached_files_object_id_object_type" ), ) + op.create_index( + op.f("ix_cached_files_object_id"), "cached_files", ["object_id"], unique=False + ) + op.create_index( + op.f("ix_cached_files_object_type"), + "cached_files", + ["object_type"], + unique=False, + ) # ### end Alembic commands ### def downgrade(): # ### commands auto generated by Alembic - please adjust! ### op.drop_table("cached_files") + op.drop_index("ix_cached_files_object_id") + op.drop_index("ix_cached_files_object_type") # ### end Alembic commands ### diff --git a/src/app/models.py b/src/app/models.py index 1420c1b..d357454 100644 --- a/src/app/models.py +++ b/src/app/models.py @@ -14,6 +14,6 @@ class CachedFile(ormar.Model): constraints = [ormar.UniqueColumns("object_id", "object_type")] id: int = ormar.Integer(primary_key=True) # type: ignore - object_id: int = ormar.Integer() # type: ignore - object_type: str = ormar.String(max_length=8) # type: ignore + object_id: int = ormar.Integer(index=True) # type: ignore + object_type: str = ormar.String(max_length=8, index=True) # type: ignore data: dict = ormar.JSON() # type: ignore diff --git a/src/app/views.py b/src/app/views.py index 4ac4489..2736b4b 100644 --- a/src/app/views.py +++ b/src/app/views.py @@ -29,7 +29,7 @@ async def get_cached_file(object_id: int, object_type: str): ) if not cached_file: - cached_file = await cache_file_by_book_id(object_id, object_type) + cached_file = await cache_file_by_book_id({}, object_id, object_type) if not cached_file: raise HTTPException(status_code=status.HTTP_404_NOT_FOUND) @@ -44,7 +44,7 @@ async def download_cached_file(object_id: int, object_type: str): ) if not cached_file: - cached_file = await cache_file_by_book_id(object_id, object_type) + cached_file = await cache_file_by_book_id({}, object_id, object_type) if not cached_file: raise HTTPException(status_code=status.HTTP_404_NOT_FOUND) diff --git a/src/core/setup_arq.py b/src/core/setup_arq.py index a8388f3..1920612 100644 --- a/src/core/setup_arq.py +++ b/src/core/setup_arq.py @@ -24,4 +24,4 @@ class WorkerSettings: on_startup = startup on_shutdown = shutdown redis_settings = get_redis_settings() - max_jobs = 4 + max_jobs = 2