Skip to content

Commit b3208f4

Browse files
authored
fix: remove join in currency queries (#3294)
* fix: remove join in currency queries * chore: generate
1 parent aebad9e commit b3208f4

4 files changed

Lines changed: 22 additions & 54 deletions

File tree

examples/python/guides/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ package-mode = false
66

77
[tool.poetry.dependencies]
88
python = "^3.10"
9-
hatchet-sdk = "^1.28.2"
9+
hatchet-sdk = "^1.29.0"
1010
# LLM integrations
1111
openai = "^1.0.0"
1212
anthropic = "^0.39.0"

examples/typescript/guides/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"lint:fix": "eslint . --fix"
99
},
1010
"dependencies": {
11-
"@hatchet-dev/typescript-sdk": "^1.16.0",
11+
"@hatchet-dev/typescript-sdk": "^1.17.0",
1212
"@anthropic-ai/sdk": "^0.32.1",
1313
"@ai-sdk/openai": "^1.0.0",
1414
"@browserbasehq/sdk": "^2.7.0",

pkg/repository/sqlcv1/concurrency.sql

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -323,24 +323,16 @@ WITH locked_workflow_concurrency_slots AS (
323323
ORDER BY strategy_id, workflow_version_id, workflow_run_id
324324
FOR UPDATE
325325
), eligible_running_slots AS (
326-
SELECT wsc.*
326+
SELECT *
327327
FROM (
328-
SELECT DISTINCT key
328+
SELECT *,
329+
ROW_NUMBER() OVER (PARTITION BY key ORDER BY sort_id DESC) as rn
329330
FROM locked_workflow_concurrency_slots
330331
WHERE
331332
tenant_id = @tenantId::uuid
332333
AND strategy_id = @strategyId::bigint
333-
) distinct_keys
334-
JOIN LATERAL (
335-
SELECT *
336-
FROM locked_workflow_concurrency_slots wcs_all
337-
WHERE
338-
wcs_all.key = distinct_keys.key
339-
AND wcs_all.tenant_id = @tenantId::uuid
340-
AND wcs_all.strategy_id = @strategyId::bigint
341-
ORDER BY wcs_all.sort_id DESC
342-
LIMIT @maxRuns::int
343-
) wsc ON true
334+
) ranked
335+
WHERE rn <= @maxRuns::int
344336
), slots_to_run AS (
345337
SELECT
346338
*
@@ -565,24 +557,16 @@ WITH locked_workflow_concurrency_slots AS (
565557
ORDER BY strategy_id, workflow_version_id, workflow_run_id
566558
FOR UPDATE
567559
), eligible_running_slots AS (
568-
SELECT wsc.*
560+
SELECT *
569561
FROM (
570-
SELECT DISTINCT key
562+
SELECT *,
563+
ROW_NUMBER() OVER (PARTITION BY key ORDER BY sort_id ASC) as rn
571564
FROM locked_workflow_concurrency_slots
572565
WHERE
573566
tenant_id = @tenantId::uuid
574567
AND strategy_id = @strategyId::bigint
575-
) distinct_keys
576-
JOIN LATERAL (
577-
SELECT *
578-
FROM locked_workflow_concurrency_slots wcs_all
579-
WHERE
580-
wcs_all.key = distinct_keys.key
581-
AND wcs_all.tenant_id = @tenantId::uuid
582-
AND wcs_all.strategy_id = @strategyId::bigint
583-
ORDER BY wcs_all.sort_id ASC
584-
LIMIT @maxRuns::int
585-
) wsc ON true
568+
) ranked
569+
WHERE rn <= @maxRuns::int
586570
), slots_to_run AS (
587571
SELECT
588572
*

pkg/repository/sqlcv1/concurrency.sql.go

Lines changed: 10 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)