Title: perf(webapp): batch declarative schedule cleanup queries by ericallam · Pull Request #4522 · triggerdotdev/trigger.dev · GitHub
Open Graph Title: perf(webapp): batch declarative schedule cleanup queries by ericallam · Pull Request #4522 · triggerdotdev/trigger.dev
X Title: perf(webapp): batch declarative schedule cleanup queries by ericallam · Pull Request #4522 · triggerdotdev/trigger.dev
Description: Summary syncDeclarativeSchedules runs on every background-worker creation (every deploy, and every file save during trigger dev). It issued one instance-delete per declarative schedule the current worker no longer declares, in a loop, and the overwhelming majority of those deletes matched zero rows. This collapses the loop into at most two set-based statements and skips the instance delete entirely when the current environment owns no instance of the schedule. Why so many, and mostly no-op The loop runs once per entry in missingSchedules, which starts as every DECLARATIVE schedule for the whole project across all its environments (the query filters only by projectId). A schedule leaves that set only when a declared task matches it by taskIdentifier and the schedule already has an instance in the current environment. That last clause is the amplifier. When a task's schedule has no instance in the current environment, the create branch inserts a brand-new TaskSchedule row with an instance for this environment rather than adding an instance to the existing row. So the same scheduled task, once it has run in dev and been deployed to prod, exists as two separate schedule rows: one carrying a dev instance, one carrying a prod instance. On a dev worker sync of that project: the dev-instance row matches the declared task and is removed from the set the prod-instance row has the same taskIdentifier but no dev instance, so it stays in the set and gets deleteMany(taskScheduleId = prodRow, environmentId = dev), which matches zero rows So every declarative task that has been synced in another environment contributes one guaranteed no-op delete per sync, and the count scales with (declarative tasks x environments), plus any leftover rows from renamed or removed tasks. A project does not need to have dropped a schedule to generate these; it just needs the same declarative tasks present in more than one environment, which is the normal develop-in-dev, deploy-to-prod case. Fix The candidate schedules are already loaded with their instances, so the branch is decided in memory: schedules with no instances (or only current-environment instances) are removed in a single taskSchedule.deleteMany schedules that still have another environment's instance have only the current environment's instance detached, in a single taskScheduleInstance.deleteMany, and only when such an instance actually exists Behavior is unchanged (cascade delete still removes the instances of a deleted schedule); the difference is statement count. A zero-row delete writes no WAL and creates no dead tuples, so the removed work was pure query and commit overhead. Verified with a testcontainer test (red before, green after) counting the emitted deletes across the no-op, batched-detach, and schedule-delete cases, and end to end through trigger dev: three declarative schedules created, surviving a re-sync, then two removed in a single batched delete with the third preserved.
Open Graph Description: Summary syncDeclarativeSchedules runs on every background-worker creation (every deploy, and every file save during trigger dev). It issued one instance-delete per declarative schedule the current ...
X Description: Summary syncDeclarativeSchedules runs on every background-worker creation (every deploy, and every file save during trigger dev). It issued one instance-delete per declarative schedule the current ...
Opengraph URL: https://github.com/triggerdotdev/trigger.dev/pull/4522
X: @github
Domain: github.com
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react-reconciler,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@d5750093facf |
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:6b5ffaf8-b578-f8f2-dfdf-6f04cf7b33c0 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | B662:1F5CA2:6E971E:A2D28B:6AFAF45D |
| html-safe-nonce | dc550bc1ce2c42e6bc70eebc8464d331bf0249fc961a7b233759206b896c0124 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCNjYyOjFGNUNBMjo2RTk3MUU6QTJEMjhCOjZBRkFGNDVEIiwidmlzaXRvcl9pZCI6IjkwMzkzNDY1ODQyMzUyMDk4MjEiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | f81dadb6109607910aa2c6e8b0066f0ce94b101ddcc9cb70eae4a6929ab0316d |
| hovercard-subject-tag | pull_request:4221806893 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/triggerdotdev/trigger.dev/pull/4522/files |
| twitter:image | https://avatars.githubusercontent.com/u/534?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/534?s=400&v=4 |
| og:image:alt | Summary syncDeclarativeSchedules runs on every background-worker creation (every deploy, and every file save during trigger dev). It issued one instance-delete per declarative schedule the current ... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 0178036d8230524a18422872393ab7e708443ae4c2047f758560a2db870c1913 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/triggerdotdev/trigger.dev git https://github.com/triggerdotdev/trigger.dev.git |
| octolytics-dimension-user_id | 95297378 |
| octolytics-dimension-user_login | triggerdotdev |
| octolytics-dimension-repository_id | 572570113 |
| octolytics-dimension-repository_nwo | triggerdotdev/trigger.dev |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 572570113 |
| octolytics-dimension-repository_network_root_nwo | triggerdotdev/trigger.dev |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | a85e96a83bed7871993e6b1ffda24105928eee17 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width