add index to speed up get last attempt (#3636)

* add index to speed up get last attempt

* use descending order

* put back unique param

* how did this not get formatted?

---------

Co-authored-by: Richard Kuo (Danswer) <rkuo@onyx.app>
This commit is contained in:
rkuo-danswer 2025-01-08 16:56:55 -08:00 committed by GitHub
parent 7f6ef1ff57
commit 97a963b4bf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 43 additions and 0 deletions

View File

@ -0,0 +1,35 @@
"""add composite index for index attempt time updated
Revision ID: 369644546676
Revises: 2955778aa44c
Create Date: 2025-01-08 15:38:17.224380
"""
from alembic import op
from sqlalchemy import text
# revision identifiers, used by Alembic.
revision = "369644546676"
down_revision = "2955778aa44c"
branch_labels: None = None
depends_on: None = None
def upgrade() -> None:
op.create_index(
"ix_index_attempt_ccpair_search_settings_time_updated",
"index_attempt",
[
"connector_credential_pair_id",
"search_settings_id",
text("time_updated DESC"),
],
unique=False,
)
def downgrade() -> None:
op.drop_index(
"ix_index_attempt_ccpair_search_settings_time_updated",
table_name="index_attempt",
)

View File

@ -18,6 +18,7 @@ from fastapi_users_db_sqlalchemy.access_token import SQLAlchemyBaseAccessTokenTa
from fastapi_users_db_sqlalchemy.generics import TIMESTAMPAware from fastapi_users_db_sqlalchemy.generics import TIMESTAMPAware
from sqlalchemy import Boolean from sqlalchemy import Boolean
from sqlalchemy import DateTime from sqlalchemy import DateTime
from sqlalchemy import desc
from sqlalchemy import Enum from sqlalchemy import Enum
from sqlalchemy import Float from sqlalchemy import Float
from sqlalchemy import ForeignKey from sqlalchemy import ForeignKey
@ -813,6 +814,13 @@ class IndexAttempt(Base):
"connector_credential_pair_id", "connector_credential_pair_id",
"time_created", "time_created",
), ),
Index(
"ix_index_attempt_ccpair_search_settings_time_updated",
"connector_credential_pair_id",
"search_settings_id",
desc("time_updated"),
unique=False,
),
) )
def __repr__(self) -> str: def __repr__(self) -> str: