Skip to content

Hogged transaction for less time for automation email processing - #32569

Open
EvanHahn wants to merge 1 commit into
mainfrom
automations-trackEmailDeliveredAndOpened-hold-transaction-for-less-time
Open

EvanHahn wants to merge 1 commit into
mainfrom
automations-trackEmailDeliveredAndOpened-hold-transaction-for-less-time

Conversation

@EvanHahn

@EvanHahn EvanHahn commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

towards https://linear.app/ghost/issue/NY-1704

Small performance improvement.

When we process automation emails' delivered/opened events, we use a database transaction. This moves a small loop out of that transaction to shorten the time we hold it.

I think this is useful on its own, but will make an upcoming change a little simpler.

towards https://linear.app/ghost/issue/NY-1704

Small performance improvement.

When we process automation emails' delivered/opened events, we use a
database transaction. This moves a small loop out of that transaction to
shorten the time we hold it.

I think this is useful on its own, but will make an upcoming change a
little simpler.
@coderabbitai

coderabbitai Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

Run configuration
  • Source mode: Auto
  • Repository: TryGhost/Ghost
  • Branch: main
  • File: .coderabbit.yaml
  • Commit: b2e34d2
  • Layers: Repository YAML
  • Review profile: QUIET
  • Plan: Essentials
  • Run ID: 3ed7ed4c-72d7-44a5-8362-95700041dbb5
Commits

Reviewing files that changed from the base of the PR and between ef4edea and ef4edea.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review

No actionable comments were generated in the recent review.

Walkthrough

trackEmailDeliveredAndOpened now collects revision IDs associated with opened events before beginning the transaction. The transaction still locks revisions before recipients, then updates delivery and open timestamps and increments open counts.

Possibly related PRs

  • TryGhost/Ghost#32478: Moves action-revision locking into repository2.lockActionRevisions within trackEmailDeliveredAndOpened.

Suggested reviewers: cmraible, troyciesco

Merge Risk: Minimal · up to ef4ed

The change only shortens transaction time without moving database reads or concurrency protection, so it is mergeable.

Pre-merge checks: Passed 7
Check name Status Explanation
Title check Passed The title clearly describes the main change: reducing the time spent in a database transaction during automation email processing.
Description check Passed The description accurately explains the performance improvement and the transaction change for automation email delivered/opened events.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Type-Safe Boundaries Passed The PR only relocates the existing revisionIds loop from inside the transaction to before it in database-automations-repository.ts. It adds no new boundary ingress, Zod bypass, any, unchecked as…
New Files Are Typescript Passed The pull request changes one pre-existing TypeScript file: ghost/core/server/services/automations/database-automations-repository.ts. It adds no .js, .jsx, .cjs, or .mjs source file.
Tooling Ownership Passed PASS. The PR changes only ghost/core/server/services/automations/database-automations-repository.ts. This is application behavior in the owning Core subsystem, not a script, tool, or shared configur…
Full details: Type-Safe Boundaries

Explanation

The PR only relocates the existing revisionIds loop from inside the transaction to before it in database-automations-repository.ts. It adds no new boundary ingress, Zod bypass, any, unchecked assertion, @ts-ignore, or duplicated schema type. The map remains an internal typed ReadonlyDeep<Map<string, AutomatedEmailEvents>> contract, and the external-event transformation already exists in the unchanged batch processor.

Full details: Tooling Ownership

Explanation

PASS. The PR changes only ghost/core/server/services/automations/database-automations-repository.ts. This is application behavior in the owning Core subsystem, not a script, tool, or shared configuration. No tooling placement or execution problem is introduced.

Finishing Touches
Generate docstrings
  • Commit to this branch
  • Create a new PR
Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info
Run configuration
  • Source mode: Auto
  • Repository: TryGhost/Ghost
  • Branch: main
  • File: .coderabbit.yaml
  • Commit: b2e34d2
  • Layers: Repository YAML
  • Review profile: QUIET
  • Plan: Essentials
  • Run ID: 04032190-a006-4eb6-bfe2-116b1fbcb3b7
Commits

Reviewing files that changed from the base of the PR and between b2e34d2 and ef4edea.

Files selected for processing: 1
  • ghost/core/server/services/automations/database-automations-repository.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.

Recent review details
Context from checks skipped due to timeout: 12
  • GitHub Check: Build Docker Images
  • GitHub Check: Build Ghost-CLI archive
  • GitHub Check: Legacy tests (Node 22.23.4, mysql8)
  • GitHub Check: Legacy tests (Node 24.20.0, mysql8)
  • GitHub Check: Acceptance tests (Node 24.20.0, mysql8)
  • GitHub Check: Unit tests (Node 24.20.0)
  • GitHub Check: Acceptance tests (Node 22.23.4, mysql8)
  • GitHub Check: Unit tests (Node 22.23.4)
  • GitHub Check: Lint
  • GitHub Check: CodeRabbit
  • GitHub Check: Detect Tinybird changes
  • GitHub Check: Analyze (javascript-typescript)
Additional context used
Code guidelines: 5
docs/practices/error-handling.md — configured
tools/README.md — configured
ghost/core/server/services/README.md — auto-discovered
docs/codebase/jobs.md — configured
docs/codebase/monorepo-structure.md — configured
Path-based instructions: 8
Review new or changed service boundaries for explicit dependency ownership, deterministic/idempotent initialisation, boot ordering, transaction and event semantics, cache coherence, and restart/multi-instance safety.

CodeRabbit configuration file

Files:

  • ghost/core/server/services/automations/database-automations-repository.ts
Review lens: "where does this data become trusted?" Boundary data (HTTP input, external API/SDK responses, env/config, DB/filesystem reads, queue/webhook/event payloads) is `unknown` until validated — Zod by default.

CodeRabbit configuration file

Files:

  • ghost/core/server/services/automations/database-automations-repository.ts
Prioritise concrete correctness, security, data-integrity, compatibility, and regression risks.

CodeRabbit configuration file

Files:

  • ghost/core/server/services/automations/database-automations-repository.ts
Source excerpt: Use that fallback when there is no safe, useful message.

CodeRabbit inference engine (docs/practices/error-handling.md)

Files:

  • ghost/core/server/services/automations/database-automations-repository.ts
Applicability reference: AGENTS.md: # AGENTS.md **Repository tooling:** read the [tooling ownership guide](tools/README.md) Source excerpt: | Job | Home | How it runs | | ---------------------------------------------------...

CodeRabbit inference engine (tools/README.md)

Files:

  • ghost/core/server/services/automations/database-automations-repository.ts
Applicability reference: AGENTS.md: # AGENTS.md **Ghost Core:** use the [server map](docs/codebase/monorepo-structure.md#ghost-core) and read the [services guide](ghost/core/server/services/README.md) before Source excerpt...

CodeRabbit inference engine (ghost/core/server/services/README.md)

Files:

  • ghost/core/server/services/automations/database-automations-repository.ts
Source excerpt: Jobs run in-process and share the main process's initialized services.

CodeRabbit inference engine (docs/codebase/jobs.md)

Files:

  • ghost/core/server/services/automations/database-automations-repository.ts
Applicability reference: AGENTS.md: # AGENTS.md Start with: [Monorepo structure](docs/codebase/monorepo-structure.md) AGENTS.md: # AGENTS.md **Ghost Core:** use the [server map](docs/codebase/monorepo-structure.md#ghost-co...

CodeRabbit inference engine (docs/codebase/monorepo-structure.md)

Files:

  • ghost/core/server/services/automations/database-automations-repository.ts
Additional comments: 1
ghost/core/server/services/automations/database-automations-repository.ts: 1

579-585: LGTM!

Also applies to: 587-587, 589-589

@nx-cloud

nx-cloud Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

🤖 Nx Cloud AI Fix

Ensure the fix-ci command is configured to always run in your CI pipeline to get automatic fixes in future runs. For more information, please see https://nx.dev/ci/features/self-healing-ci


View your CI Pipeline Execution ↗ for commit ef4edea

Command Status Duration Result
nx run ghost:test:ci:integration ✅ Succeeded 2m 37s View ↗
nx run ghost:test:integration ✅ Succeeded 1m 56s View ↗
nx run ghost:test:bullmq:scenarios ✅ Succeeded 58s View ↗
nx run ghost:test:bullmq ✅ Succeeded 50s View ↗
nx run ghost:test:ci:e2e ✅ Succeeded 5m 26s View ↗
nx run ghost:test:e2e ✅ Succeeded 3m 48s View ↗
nx run ghost:test:legacy ✅ Succeeded 2m 16s View ↗
nx run ghost:test:ci:unit ✅ Succeeded 1m 13s View ↗
Additional runs (8) ✅ Succeeded ... View ↗

💡 Verify your cache is correct by running tasks in a sandbox. Read docs ↗


☁️ Nx Cloud last updated this comment at 2026-11-04 19:54:55 UTC

@codecov

codecov Bot commented Nov 4, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.14%. Comparing base (b2e34d2) to head (ef4edea).

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #32569      +/-   ##
==========================================
+ Coverage   85.89%   86.14%   +0.24%     
==========================================
  Files        1414     1414              
  Lines       53630    53630              
  Branches     9239     9239              
==========================================
+ Hits        46063    46197     +134     
+ Misses       6421     6335      -86     
+ Partials     1146     1098      -48     
Flag Coverage Δ
e2e-tests 73.25% <100.00%> (-0.02%) ⬇️
unit-tests 69.40% <80.00%> (+0.18%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant