Skip to content

Commit

Permalink
add index to speed up get last attempt (#3636)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
rkuo-danswer and Richard Kuo (Danswer) authored Jan 9, 2025
1 parent 7f6ef1f commit 97a963b
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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",
)
8 changes: 8 additions & 0 deletions backend/onyx/db/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from fastapi_users_db_sqlalchemy.generics import TIMESTAMPAware
from sqlalchemy import Boolean
from sqlalchemy import DateTime
from sqlalchemy import desc
from sqlalchemy import Enum
from sqlalchemy import Float
from sqlalchemy import ForeignKey
Expand Down Expand Up @@ -813,6 +814,13 @@ class IndexAttempt(Base):
"connector_credential_pair_id",
"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:
Expand Down

0 comments on commit 97a963b

Please sign in to comment.