Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eagerly load CCpair connectors #3531

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion backend/onyx/db/connector_credential_pair.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from sqlalchemy import Select
from sqlalchemy import select
from sqlalchemy.orm import aliased
from sqlalchemy.orm import joinedload
from sqlalchemy.orm import Session

from onyx.configs.constants import DocumentSource
Expand Down Expand Up @@ -90,15 +91,22 @@ def get_connector_credential_pairs(
user: User | None = None,
get_editable: bool = True,
ids: list[int] | None = None,
eager_load_connector: bool = False,
) -> list[ConnectorCredentialPair]:
stmt = select(ConnectorCredentialPair).distinct()

if eager_load_connector:
stmt = stmt.options(joinedload(ConnectorCredentialPair.connector))

stmt = _add_user_filters(stmt, user, get_editable)

if not include_disabled:
stmt = stmt.where(
ConnectorCredentialPair.status == ConnectorCredentialPairStatus.ACTIVE
) # noqa
)
if ids:
stmt = stmt.where(ConnectorCredentialPair.id.in_(ids))

return list(db_session.scalars(stmt).all())


Expand Down
2 changes: 1 addition & 1 deletion backend/onyx/server/documents/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -1058,7 +1058,7 @@ def get_basic_connector_indexing_status(
_: User = Depends(current_user),
db_session: Session = Depends(get_session),
) -> list[BasicCCPairInfo]:
cc_pairs = get_connector_credential_pairs(db_session)
cc_pairs = get_connector_credential_pairs(db_session, eager_load_connector=True)
return [
BasicCCPairInfo(
has_successful_run=cc_pair.last_successful_index_time is not None,
Expand Down
Loading