Skip to content

feat(data-access): add TicketSuggestion bulk accessors allBySuggestionIds and allByTicketIds (SITES-44690)#1804

Merged
prithipalpatwal merged 3 commits into
mainfrom
feat/SITES-44690-data-models
Jul 13, 2026
Merged

feat(data-access): add TicketSuggestion bulk accessors allBySuggestionIds and allByTicketIds (SITES-44690)#1804
prithipalpatwal merged 3 commits into
mainfrom
feat/SITES-44690-data-models

Conversation

@prithipalpatwal

@prithipalpatwal prithipalpatwal commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Jira: SITES-44690

Summary

Adds two bulk query methods to TicketSuggestionCollection to replace raw postgrestClient calls in spacecat-api-service.

Both methods use this.all() with op.in (the established pattern from FixEntityCollection.allByOpportunityIds) — no direct postgrestService access in the subclass.

Changes

  • allBySuggestionIds(suggestionIds) — pre-flight duplicate check before ticket creation
  • allByTicketIds(ticketIds) — bulk-load bridge rows when listing tickets

Alignment

Schema aligned with mysticat-data-service PR #720: field names map automatically (suggestionIdsuggestion_id, ticketIdticket_id) via the applyWhere attrs proxy.

@github-actions

Copy link
Copy Markdown

This PR will trigger a minor release when merged.

@prithipalpatwal prithipalpatwal changed the title feat(data-access): add TaskManagementConnection, Ticket, TicketSuggestion, IdempotencyKey, OAuthNonce models (SITES-44690) feat(data-access): add TicketSuggestion bulk accessors and Ticket.statusSyncedAt (SITES-44690) Jul 13, 2026
@prithipalpatwal prithipalpatwal changed the title feat(data-access): add TicketSuggestion bulk accessors and Ticket.statusSyncedAt (SITES-44690) feat(data-access): add TicketSuggestion bulk accessors allBySuggestionIds and allByTicketIds (SITES-44690) Jul 13, 2026
…essors to TicketSuggestionCollection (SITES-44690)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@prithipalpatwal
prithipalpatwal force-pushed the feat/SITES-44690-data-models branch from 1eb97c4 to 5e4941e Compare July 13, 2026 05:41
…stion accessors (SITES-44690)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

@MysticatBot MysticatBot 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.

Hey @prithipalpatwal,

⚠ Degraded review - no spec document was found for this change (searched the PR links, the touched repos' docs, the architecture/guidelines docs, and linked Jira). This review covers code-level quality but could not validate the change against an agreed design, so confidence is reduced. Add a spec link (PR template section 4) and re-request review for a full-confidence pass.

Verdict: Request changes - missing IN-filter chunking diverges from the reference pattern and risks production failures at scale.
Complexity: LOW - small, single-service, follows established pattern.
Changes: Adds two bulk query methods (allBySuggestionIds, allByTicketIds) to TicketSuggestionCollection using op.in via this.all() (2 files).

Must fix before merge

  1. [Important] Missing IN-filter chunking for large ID arrays - ticket-suggestion.collection.js:35-44,57-66 (details inline)
Non-blocking (3): minor issues and suggestions
  • nit: Input validation uses ad-hoc Array.isArray check instead of guardArray utility (the reference allByOpportunityIds uses guardArray which throws on invalid input and validates element types) - ticket-suggestion.collection.js:35,57
  • nit: Missing deduplication of input IDs before querying (reference uses [...new Set(ids)]) - ticket-suggestion.collection.js:38,60
  • nit: Test file uses direct import { stub } from 'sinon' instead of documented sinon.createSandbox() with afterEach(() => sandbox.restore()) pattern per root CLAUDE.md - ticket-suggestion.collection.test.js:16

Skill: pr-review | Model: us.anthropic.claude-opus-4-6-v1[1m] | Duration: 1m 46s | Cost: $3.87 | Commit: 7141a2846cb0e49a2b86ef39927409f9b6ae0084
If this code review was useful, please react with 👍. Otherwise, react with 👎.

try {
return await this.all(
{},
{ where: (attrs, op) => op.in(attrs.suggestionId, suggestionIds) },

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

issue (blocking): Both allBySuggestionIds and allByTicketIds pass the full ID array to a single op.in() call without chunking. The reference pattern (FixEntityCollection.allByOpportunityIds) explicitly chunks at IN_FILTER_CHUNK_SIZE = 50 because PostgREST serializes IN-filters into the URL, and large ID lists exceed the ~8KB URL length limit.

Since these methods are described as "bulk" operations (pre-flight duplicate check, bulk-load bridge rows), callers can plausibly pass 100+ UUIDs.

Fix: adopt the same chunking pattern from the reference:

const uniqueIds = [...new Set(suggestionIds)];
const chunks = [];
for (let i = 0; i < uniqueIds.length; i += IN_FILTER_CHUNK_SIZE) {
  chunks.push(uniqueIds.slice(i, i + IN_FILTER_CHUNK_SIZE));
}
const results = await Promise.all(
  chunks.map((chunk) => this.all(
    {},
    { where: (attrs, op) => op.in(attrs.suggestionId, chunk) },
  )),
);
return results.flat();

This also applies to allByTicketIds below (same pattern, same fix).

@MysticatBot MysticatBot added ai-reviewed Reviewed by AI complexity:low AI-assessed PR complexity: LOW labels Jul 13, 2026
…erence pattern (SITES-44690)

- Add IN-filter chunking (size 50) with parallel Promise.all to prevent
  URL-length failures on large ID arrays
- Replace ad-hoc Array.isArray guard with guardArray() for consistent
  ValidationError on invalid input
- Deduplicate input IDs with [...new Set()] before chunking
- Switch test stubs from bare sinon.stub() to sandbox pattern with afterEach restore
- Add test cases for ValidationError, deduplication, and chunking behaviour

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

@MysticatBot MysticatBot 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.

Hey @prithipalpatwal,

⚠ Degraded review - no spec document was found for this change (searched the PR links, the touched repos' docs, the architecture/guidelines docs, and linked Jira). This review covers code-level quality but could not validate the change against an agreed design, so confidence is reduced. Add a spec link (PR template section 4) and re-request review for a full-confidence pass.

Verdict: Approve - all prior findings addressed, implementation follows the established pattern cleanly.
Complexity: HIGH - medium diff; models/ path fires Database/Schema risk signal.
Changes: Adds two bulk query methods (allBySuggestionIds, allByTicketIds) to TicketSuggestionCollection with chunking, dedup, and validation (2 files).

Non-blocking (1): minor issues and suggestions
  • nit: The chunking loop (build chunks array, slice at IN_FILTER_CHUNK_SIZE) is duplicated verbatim across both methods. Tolerable at two instances (the reference pattern in FixEntityCollection inlines it the same way), but a small private helper would reduce drift surface if the logic ever changes - ticket-suggestion.collection.js:40-43,74-77

Previously flagged, now resolved

  • IN-filter chunking at size 50 now present
  • guardArray validation replaces ad-hoc Array.isArray check
  • Deduplication via [...new Set(ids)] before querying
  • Test file uses sinon.createSandbox() with afterEach restore

Skill: pr-review | Model: us.anthropic.claude-opus-4-6-v1[1m] | Duration: 2m 50s | Cost: $4.30 | Commit: 5b30c85680a45e2a724bc63a33aec4a8ceb29525
If this code review was useful, please react with 👍. Otherwise, react with 👎.

@MysticatBot MysticatBot added complexity:high High complexity PR and removed complexity:low AI-assessed PR complexity: LOW labels Jul 13, 2026
@prithipalpatwal
prithipalpatwal merged commit 99387f6 into main Jul 13, 2026
6 checks passed
@prithipalpatwal
prithipalpatwal deleted the feat/SITES-44690-data-models branch July 13, 2026 07:22
solaris007 pushed a commit that referenced this pull request Jul 13, 2026
## [@adobe/spacecat-shared-data-access-v4.7.0](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-data-access-v4.6.0...@adobe/spacecat-shared-data-access-v4.7.0) (2026-07-13)

### Features

* **data-access:** add TicketSuggestion bulk accessors allBySuggestionIds and allByTicketIds (SITES-44690) ([#1804](#1804)) ([99387f6](99387f6))
@solaris007

Copy link
Copy Markdown
Member

🎉 This PR is included in version @adobe/spacecat-shared-data-access-v4.7.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Labels

ai-reviewed Reviewed by AI complexity:high High complexity PR released

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants