Skip to content

Commit

Permalink
Fix cursor fetch query
Browse files Browse the repository at this point in the history
  • Loading branch information
isra17 committed May 9, 2024
1 parent fa4b783 commit 4b4c351
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions src/saturn_engine/stores/jobs_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,21 +189,15 @@ def fetch_cursors_states(
) -> CursorsStates:
# Generate a query for each jobs so we can UNION them.
fetch_stmts = []
jobs = session.execute(
select(Job.name, Job.job_definition_name).where(Job.name.in_(query.keys()))
).all()
job_names = {j.name: j.job_definition_name for j in jobs}
for job, cursors in query.items():
job_name = job_names.get(job) or job
fetch_stmts.append(
select(JobCursorState, sa.func.coalesce(Job.name, job).label("name"))
.join(
Job,
Job.job_definition_name == JobCursorState.job_definition_name,
isouter=True,
)
.where(
sa.or_(
Job.name == job,
sa.and_(
Job.name.is_(None), JobCursorState.job_definition_name == job
),
),
select(JobCursorState, sa.literal(job).label("name")).where(
JobCursorState.job_definition_name == job_name,
JobCursorState.cursor.in_(cursors),
)
)
Expand Down

0 comments on commit 4b4c351

Please sign in to comment.