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

Fix cursor fetch query #425

Merged
merged 1 commit into from
May 9, 2024
Merged
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
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
Loading