Skip to content

Batch related database reads and transaction writes - #1851

Merged
stefan-burke merged 5 commits into
mainfrom
refactor/unify-shared-paths
Jul 17, 2026
Merged

stefan-burke merged 5 commits into
mainfrom
refactor/unify-shared-paths

Conversation

@stefan-burke

@stefan-burke stefan-burke commented Jul 17, 2026

Copy link
Copy Markdown
Member

What changed

  • Use the batch group-listing query for both one group and many groups.
  • Load only the three needed package-display columns in one bounded database read.
  • Skip package display queries for standalone ticket markers.
  • Use transaction batches for link replacement and saved answer text.
  • Remove wrapper functions that only renamed existing configuration, cache, cookie, and query helpers.
  • Run boot checks from the declared boot-check list.
  • Give both exported single-group loaders one explicit public contract.
  • Use one descriptive alias for full-row group queries.
  • Remove a redundant second process signal from the mutation supervisor test.

Why

The same concepts had separate implementations for one item and many items, or extra names around an existing helper. Keeping one path makes their behavior consistent and removes 36 lines from src while doing the same work.

Package display loading now takes one narrow database round trip for several package IDs instead of one round trip per ID. Standalone tickets take no package display round trip.

Tests

  • Added regression tests for loading several package displays in one round trip and standalone markers in zero round trips.
  • Transaction failure tests cover both single statements and batches.
  • The free-text rollback test fails after old answers are deleted and verifies that the whole prior answer set is restored.
  • The mutation supervisor signal test no longer races a second kill against the child exit.
  • deno task precommit passes.

Summary by CodeRabbit

  • Performance
    • Improved package display, group listing membership, and package pricing lookups by batching database requests to reduce repeated loading.
    • Improved database write efficiency by batching transaction operations.
  • Bug Fixes
    • Updated the public contact page’s Botpoison key to use shared configuration.
    • Treat missing/unknown package groups as “hide listings” for package privacy decisions.
    • Kept secure session-cookie behavior while simplifying cookie naming.
  • Tests
    • Updated integration and unit tests for the new batched pricing/display paths and write-based transaction failure injection.

@coderabbitai

coderabbitai Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

The pull request batches package, listing, attribute, and transactional database operations, updates Botpoison and cookie configuration access, and simplifies boot, user, and settings helpers with corresponding test updates.

Changes

Batched data access

Layer / File(s) Summary
Package display batching
src/features/api/payment-processing/package-pricing.ts, src/shared/db/groups.ts, src/shared/package-privacy.ts, test/shared/db/groups.test.ts
Package pricing and privacy checks use batched package-display lookups; tests verify round trips, empty inputs, and cache invalidation.
Group listing batching
src/shared/db/groups.ts
Group listings are loaded through a batched map-based query, while single-group loaders delegate to it.
Database helper consolidation
src/shared/db/attributes.ts, src/shared/db/users.ts, src/shared/db/groups.ts
Attribute ID queries use queryIdColumn, getAllUsers directly reads from usersCache, and cached group columns are explicitly aliased.

Transactional batch execution

Layer / File(s) Summary
Transactional write batching
src/shared/db/link-table.ts, src/shared/db/questions/strings.ts
Transactional link-table replacement and string interning use tx.batch, with matching documentation updates.
Batch write failure tests
test/test-utils/db-poison.ts, test/integration/servicing/atomicity.test.ts, test/lib/server-questions/listing-questions.test.ts, test/shared/db/questions/attendee-answers.test.ts
The transaction-poisoning helper intercepts batched writes, and rollback tests use the renamed write-focused helper.

Shared API and configuration cleanup

Layer / File(s) Summary
Contact and cookie configuration
src/features/public/pages.ts, src/shared/contact-form.ts, src/shared/cookies.ts, test/shared/contact-form.test.ts, test/shared/cookies.test.ts
Contact-page Botpoison keys come from shared config, the contact-form key export is removed, and secure-mode imports move to config.
Boot and settings helper updates
src/shared/boot-checks.ts, src/shared/settings-nags.ts
Boot checks run through the registered check list, and settings nags use the renamed base-item helper.

Mutation test control

Layer / File(s) Summary
Stop-signal test flow
test/scripts/mutation-isolation-supervisor.test.ts
The interrupted-child test uses the stop callback rather than explicitly killing the child process.

Estimated code review effort: 4 (Complex) | ~45 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: batching database reads and transaction writes.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/unify-shared-paths

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/shared/db/groups.ts`:
- Around line 253-254: Update the exported getActiveListingsByGroupId
declaration to explicitly use the public signature (groupId: number) =>
Promise<ListingWithCount[]>, while preserving its existing listingsInGroup(true)
implementation.

In `@test/integration/servicing/atomicity.test.ts`:
- Around line 35-38: Update the withAnswerSaveFailure matcher in the rollback
test to target the post-delete INSERT INTO attendee_answers write, or explicitly
exclude the initial DELETE, so withPoisonedTransactionWrite triggers only after
the existing answer has been removed.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: f9996505-a768-4e0b-b66b-84b5151c7d55

📥 Commits

Reviewing files that changed from the base of the PR and between 312411f and 781e0e8.

📒 Files selected for processing (19)
  • src/features/api/payment-processing/package-pricing.ts
  • src/features/public/pages.ts
  • src/shared/boot-checks.ts
  • src/shared/contact-form.ts
  • src/shared/cookies.ts
  • src/shared/db/attributes.ts
  • src/shared/db/groups.ts
  • src/shared/db/link-table.ts
  • src/shared/db/questions/strings.ts
  • src/shared/db/users.ts
  • src/shared/package-privacy.ts
  • src/shared/settings-nags.ts
  • test/integration/servicing/atomicity.test.ts
  • test/lib/server-questions/listing-questions.test.ts
  • test/shared/contact-form.test.ts
  • test/shared/cookies.test.ts
  • test/shared/db/groups.test.ts
  • test/shared/db/questions/attendee-answers.test.ts
  • test/test-utils/db-poison.ts
💤 Files with no reviewable changes (1)
  • test/shared/contact-form.test.ts

Comment thread src/shared/db/groups.ts Outdated
Comment thread test/integration/servicing/atomicity.test.ts
@stefan-burke stefan-burke changed the title Use one shared path for related reads and writes Batch related database reads and transaction writes Jul 17, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/shared/db/groups.ts (1)

494-495: 📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win

Alias the groups table in this query.

The shared DB guidelines require descriptive full singular table aliases using AS. Use an alias such as groups AS package_group here.

Proposed fix
-        SELECT ${GROUP_COLUMNS} FROM groups
+        SELECT ${GROUP_COLUMNS} FROM groups AS package_group
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/shared/db/groups.ts` around lines 494 - 495, Update the groups query near
GROUP_COLUMNS to alias the table as “groups AS package_group” using the required
descriptive singular alias syntax, and qualify any referenced columns with
package_group as needed while preserving the query behavior.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@src/shared/db/groups.ts`:
- Around line 494-495: Update the groups query near GROUP_COLUMNS to alias the
table as “groups AS package_group” using the required descriptive singular alias
syntax, and qualify any referenced columns with package_group as needed while
preserving the query behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: f4a1966f-3f5f-477b-8ca1-3889d8bfda96

📥 Commits

Reviewing files that changed from the base of the PR and between 781e0e8 and d74b70b.

📒 Files selected for processing (1)
  • src/shared/db/groups.ts

@stefan-burke

Copy link
Copy Markdown
Member Author

Updated the PR title to name the database read/write batching directly. The description now includes the explicit loader contract, the 53-line src reduction, and the post-delete free-text rollback coverage.

@stefan-burke

Copy link
Copy Markdown
Member Author

Addressed the follow-up group-query alias finding in 377ec9f. Both full-row group queries now use the same descriptive groups AS groupRecord alias, with the shared column list and filters qualified through it. Focused group/package tests and the full precommit suite pass.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 377ec9fd15

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/shared/db/groups.ts Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/shared/db/groups.ts (1)

492-500: 🚀 Performance & Scalability | 🟠 Major | ⚡ Quick win

Project only the package-display columns.

This loader selects GROUP_COLUMNS and parses each row as a full Group, but the result only uses id, hide_package_listings, and name. Use a narrow row projection and the minimal required conversion before constructing the map; otherwise this remains an unnecessary full-row read and violates the shared DB projection rule.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/shared/db/groups.ts` around lines 492 - 500, The package group loader
around packageGroups currently selects and parses full Group rows unnecessarily.
Change the rowsByIds query to project only id, hide_package_listings, and name,
then use the minimal conversion needed by the packageGroups mapping before
constructing the map; preserve the existing filtering and package-only
conditions.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@src/shared/db/groups.ts`:
- Around line 492-500: The package group loader around packageGroups currently
selects and parses full Group rows unnecessarily. Change the rowsByIds query to
project only id, hide_package_listings, and name, then use the minimal
conversion needed by the packageGroups mapping before constructing the map;
preserve the existing filtering and package-only conditions.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 3ab3bb3a-5d60-48ba-b415-ea14a78ad4d9

📥 Commits

Reviewing files that changed from the base of the PR and between 377ec9f and 07bb169.

📒 Files selected for processing (2)
  • src/shared/db/groups.ts
  • test/shared/db/groups.test.ts

@stefan-burke

Copy link
Copy Markdown
Member Author

Addressed the package-display projection finding in 61ef322. The loader now uses defineTableProjection for only id, hide_package_listings, and name, so it decrypts no unrelated group fields. The same commit removes the mutation supervisor test’s redundant second process kill, which caused the failed CI job when the first signal had already stopped the child. Focused suites and full precommit pass.

@stefan-burke
stefan-burke added this pull request to the merge queue Jul 17, 2026
Merged via the queue into main with commit 28a312b Jul 17, 2026
3 checks passed
@stefan-burke
stefan-burke deleted the refactor/unify-shared-paths branch July 17, 2026 16:39
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