Skip to content

Commit

Permalink
Account for edge case in indexing times with connectors #2190
Browse files Browse the repository at this point in the history
  • Loading branch information
pablonyx committed Aug 30, 2024
1 parent e2f4145 commit 706aed7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
22 changes: 11 additions & 11 deletions backend/danswer/background/indexing/run_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,19 +118,19 @@ def _run_indexing(
db_cc_pair = index_attempt.connector_credential_pair
db_connector = index_attempt.connector_credential_pair.connector
db_credential = index_attempt.connector_credential_pair.credential
earliest_index_time = (
db_connector.indexing_start.timestamp() if db_connector.indexing_start else 0
)

last_successful_index_time = (
db_connector.indexing_start.timestamp()
if index_attempt.from_beginning and db_connector.indexing_start is not None
else (
0.0
if index_attempt.from_beginning
else get_last_successful_attempt_time(
connector_id=db_connector.id,
credential_id=db_credential.id,
search_settings=index_attempt.search_settings,
db_session=db_session,
)
earliest_index_time
if index_attempt.from_beginning
else get_last_successful_attempt_time(
connector_id=db_connector.id,
credential_id=db_credential.id,
earliest_index=earliest_index_time,
search_settings=index_attempt.search_settings,
db_session=db_session,
)
)

Expand Down
9 changes: 4 additions & 5 deletions backend/danswer/db/connector_credential_pair.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ def get_connector_credential_pair_from_id(
def get_last_successful_attempt_time(
connector_id: int,
credential_id: int,
earliest_index: float,
search_settings: SearchSettings,
db_session: Session,
) -> float:
Expand All @@ -172,7 +173,7 @@ def get_last_successful_attempt_time(
connector_credential_pair is None
or connector_credential_pair.last_successful_index_time is None
):
return 0.0
return earliest_index

return connector_credential_pair.last_successful_index_time.timestamp()

Expand All @@ -192,11 +193,9 @@ def get_last_successful_attempt_time(
.order_by(IndexAttempt.time_started.desc())
.first()
)

if not attempt or not attempt.time_started:
connector = fetch_connector_by_id(connector_id, db_session)
if connector and connector.indexing_start:
return connector.indexing_start.timestamp()
return 0.0
return earliest_index

return attempt.time_started.timestamp()

Expand Down

0 comments on commit 706aed7

Please sign in to comment.