Skip to content

Conversation

@ankita-p17
Copy link
Contributor

@ankita-p17 ankita-p17 commented Oct 15, 2025

This is linked to the reported bug #1485

Fetched only relevant data from table to optimize the performance

Summary by CodeRabbit

  • Bug Fixes
    • Reuses the latest available invitation to improve reliability and reduce inconsistencies during connection setup.
  • Refactor
    • Invitation lookup now returns a single, deterministic result and removes unnecessary array handling.
  • Chores
    • Reduced log verbosity by moving certain messages to debug level.

@coderabbitai
Copy link

coderabbitai bot commented Oct 15, 2025

Walkthrough

Repository method getInvitationDidByOrgId now returns a single agent_invitations record via findFirst with ordering, instead of an array via findMany. Service createConnectionInvitation aligns to consume a single object, simplifying variable naming and logging to debug. Other calls are reformatted without behavioral changes.

Changes

Cohort / File(s) Summary
Repository: single-record invitation fetch
apps/connection/src/connection.repository.ts
Changed getInvitationDidByOrgId return type from Promise<agent_invitations[]> to Promise<agent_invitations>; implementation uses findFirst with orderBy instead of findMany. Reformatted getConnectionRecords and deleteMany calls; no functional change there. Minor whitespace/comment tweaks.
Service: align to single invitation object
apps/connection/src/connection.service.ts
Updated createConnectionInvitation to handle a single agent_invitations object (no array handling). Renamed legacyinvitationDidlegacyInvitationDid and typed as `string

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Client
  participant Service as ConnectionService
  participant Repo as ConnectionRepository
  participant DB as Database

  Client->>Service: createConnectionInvitation(orgId, ...)
  Service->>Repo: getInvitationDidByOrgId(orgId)
  Repo->>DB: findFirst(agent_invitations where orgId) + orderBy
  DB-->>Repo: agent_invitations (single record)
  Repo-->>Service: agent_invitations
  Service->>Service: Resolve connectionInvitationDid (invitationDid || legacyInvitationDid)
  Service-->>Client: Return invitation details
  note over Service: Logging reduced to debug
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Review the changed public method signature in apps/connection/src/connection.repository.ts for callers that may expect an array.
  • Inspect createConnectionInvitation in apps/connection/src/connection.service.ts to ensure reuse logic and logging changes preserve intended behavior.

Poem

I hopped through branches, found one invite,
No pile of carrots — just the first in sight.
A tidy fetch, a renamed string,
Debugging whispers while robins sing.
Merge time nibbles, happy rabbit spring! 🐇✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: converting array-based data fetching to single-object fetching to minimize data transfer and optimize performance during connection request creation.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/slow-connection

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5e474cd and a56a8b1.

📒 Files selected for processing (1)
  • apps/connection/src/connection.service.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/connection/src/connection.service.ts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@ankita-p17 ankita-p17 changed the title fix: Minimize data while getting connection fix: Minimize data while creating connection request Oct 15, 2025
@sonarqubecloud
Copy link

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

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

⚠️ Outside diff range comments (1)
apps/connection/src/connection.repository.ts (1)

376-387: Unify getInvitationDidByOrgId to return only invitationDid with null-safety

  • In apps/connection/src/connection.repository.ts, apps/verification/src/repositories/verification.repository.ts and apps/issuance/src/issuance.repository.ts: change the method to
    async getInvitationDidByOrgId(orgId: string): Promise<{ invitationDid: string } | null> {
      return this.prisma.agent_invitations.findFirst({
        where: { orgId },
        select: { invitationDid: true },
        orderBy: { createDateTime: 'desc' }  // verify: newest vs oldest
      });
    }
  • Update all callers to handle a null return before dereferencing.
  • Confirm with the business whether ordering should be 'desc' (newest) or 'asc' (oldest).
🧹 Nitpick comments (1)
apps/connection/src/connection.service.ts (1)

538-541: Use template strings for debug logs.

Second arg is treated as Logger context, not value. Interpolate values instead.

-      this.logger.debug('connectionInvitationDid:', connectionInvitationDid);
+      this.logger.debug(`connectionInvitationDid: ${connectionInvitationDid}`);
-
-      this.logger.debug(`logoUrl:::, ${organisation.logoUrl}`);
+      this.logger.debug(`logoUrl: ${organisation.logoUrl}`);
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c712ea6 and 5e474cd.

📒 Files selected for processing (2)
  • apps/connection/src/connection.repository.ts (2 hunks)
  • apps/connection/src/connection.service.ts (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
apps/connection/src/connection.repository.ts (2)
apps/connection/src/connection.service.ts (2)
  • getConnectionRecords (103-112)
  • deleteConnectionRecords (662-703)
apps/connection/src/connection.controller.ts (1)
  • deleteConnectionRecords (100-103)
🔇 Additional comments (1)
apps/connection/src/connection.repository.ts (1)

348-360: Good optimization: selecting only required fields.

Limiting fields in findMany aligns with the PR goal and reduces payload/IO. LGTM.

@ankita-p17 ankita-p17 linked an issue Nov 14, 2025 that may be closed by this pull request
7 tasks
Signed-off-by: Ankita Patidar <[email protected]>
@sonarqubecloud
Copy link

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

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

fix: slow connection request creation after 300K requests

2 participants