Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(delegation-index): primary key violation #15086

Merged
merged 5 commits into from
Jun 6, 2024

Conversation

Herdismaria
Copy link
Contributor

@Herdismaria Herdismaria commented Jun 4, 2024

Fix primary key violation when indexing delegations

Checklist:

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • Formatting passes locally with my changes
  • I have rebased against main before asking for a review

Summary by CodeRabbit

  • Improvements
    • Enhanced delegation handling to better identify updates based on specific conditions, improving accuracy and reliability.

@Herdismaria Herdismaria requested review from a team as code owners June 4, 2024 13:30
Copy link
Contributor

coderabbitai bot commented Jun 4, 2024

Walkthrough

The recent changes in the DelegationsIndexService class aim to improve the logic for handling existing delegations. The enhancements focus on accurately identifying updates by considering conditions related to validTo and customDelegationScopes. This refinement ensures more precise management of delegation updates.

Changes

File/Path Change Summary
libs/auth-api-lib/src/lib/delegations/delegations-index.service.ts Improved logic for handling existing delegations, with specific attention to validTo and customDelegationScopes.

Sequence Diagram(s) (Beta)

sequenceDiagram
    participant Client
    participant DelegationsIndexService
    participant Database

    Client->>DelegationsIndexService: Request to update delegation
    DelegationsIndexService->>Database: Fetch existing delegation
    Database-->>DelegationsIndexService: Return existing delegation
    alt Delegation exists
        DelegationsIndexService->>DelegationsIndexService: Check `validTo` and `customDelegationScopes`
        alt Conditions met
            DelegationsIndexService->>Database: Update delegation
            Database-->>DelegationsIndexService: Confirmation
        else Conditions not met
            DelegationsIndexService->>Client: Return error or no update needed
        end
    else Delegation does not exist
        DelegationsIndexService->>Database: Create new delegation
        Database-->>DelegationsIndexService: Confirmation
    end
    DelegationsIndexService-->>Client: Response
Loading

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@Herdismaria Herdismaria changed the title fix(delegation-index) primary key violation fix(delegation-index): primary key violation Jun 4, 2024
@datadog-island-is
Copy link

datadog-island-is bot commented Jun 4, 2024

Datadog Report

All test runs 30c278d 🔗

33 Total Test Services: 0 Failed, 32 Passed
🔻 Test Sessions change in coverage: 3 decreased, 3 increased, 126 no change

Test Services
This report shows up to 10 services
Service Name Failed Known Flaky New Flaky Passed Skipped Total Time Code Coverage Change Test Service View
air-discount-scheme-web 0 0 0 2 0 10.39s 1 no change Link
api 0 0 0 4 0 5.37s 1 no change Link
api-domains-communications 0 0 0 5 0 57.16s 1 no change Link
api-domains-driving-license 0 0 0 23 0 51.86s 1 no change Link
api-domains-license-service 0 0 0 0 0 1.16s 1 no change Link
application-api-files 0 0 0 12 0 9.9s 1 no change Link
application-core 0 0 0 90 0 36.2s 1 decreased (-0.22%) Link
application-system-api 0 0 0 111 2 4m 23.17s 1 no change Link
application-template-api-modules 0 0 0 109 0 2m 6.75s 1 decreased (-0.05%) Link
application-templates-accident-notification 0 0 0 98 0 31.66s 1 no change Link

🔻 Code Coverage Decreases vs Default Branch (3)

  • application-core - jest 78.58% (-0.22%) - Details
  • application-template-api-modules - jest 25.96% (-0.05%) - Details
  • application-templates-financial-aid - jest 15.69% (-0.03%) - Details

Copy link

codecov bot commented Jun 4, 2024

Codecov Report

Attention: Patch coverage is 0% with 4 lines in your changes missing coverage. Please review.

Project coverage is 37.05%. Comparing base (2aa0ec3) to head (f187e78).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #15086      +/-   ##
==========================================
- Coverage   37.05%   37.05%   -0.01%     
==========================================
  Files        6422     6422              
  Lines      130935   130935              
  Branches    37413    37413              
==========================================
- Hits        48523    48519       -4     
- Misses      82412    82416       +4     
Flag Coverage Δ
air-discount-scheme-web 0.00% <ø> (ø)
application-api-files 56.17% <ø> (ø)
application-core 71.76% <ø> (-0.09%) ⬇️
application-system-api 41.99% <ø> (ø)
application-template-api-modules 24.25% <ø> (+0.01%) ⬆️
application-templates-accident-notification 19.87% <ø> (ø)
clients-charge-fjs-v2 22.58% <ø> (ø)
clients-syslumenn 49.39% <ø> (ø)
cms 0.44% <ø> (ø)
cms-translations 39.74% <ø> (ø)
financial-aid-backend 56.34% <ø> (ø)
judicial-system-api 17.83% <ø> (ø)
judicial-system-formatters 81.02% <ø> (ø)
judicial-system-message 65.65% <ø> (ø)
judicial-system-types 48.65% <ø> (ø)
judicial-system-web 28.02% <ø> (ø)
services-auth-ids-api 55.18% <0.00%> (+0.18%) ⬆️
services-auth-personal-representative 48.50% <0.00%> (ø)
services-endorsements-api 55.07% <ø> (ø)
services-university-gateway 48.17% <ø> (ø)
services-user-notification 47.61% <ø> (ø)
services-user-profile 62.50% <ø> (-0.10%) ⬇️

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

Files Coverage Δ
...b/src/lib/delegations/delegations-index.service.ts 90.86% <0.00%> (-2.16%) ⬇️

... and 2 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2aa0ec3...f187e78. Read the comment docs.

Copy link
Member

@GunnlaugurG GunnlaugurG left a comment

Choose a reason for hiding this comment

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

LGTM🚀

@Herdismaria Herdismaria added the automerge Merge this PR as soon as all checks pass label Jun 5, 2024
Copy link
Contributor

@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

Outside diff range and nitpick comments (2)
libs/auth-api-lib/src/lib/delegations/delegations-index.service.ts (2)

Line range hint 464-464: Optimize the use of spread syntax in .reduce.

Using spread syntax in the accumulator of a .reduce function leads to poor performance due to O(n^2) complexity. Consider using methods like .push to accumulate values.

- return [...acc, ...delegations]
+ acc.push(...delegations)
+ return acc

Line range hint 223-224: Use optional chaining for safer code.

Consider using optional chaining to safely access nested properties. This can prevent runtime errors if some intermediate properties are null or undefined.

- if (existing && existing.validTo !== curr.validTo)
+ if (existing?.validTo !== curr.validTo)
Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 9e1ff00 and 12de1fa.

Files selected for processing (1)
  • libs/auth-api-lib/src/lib/delegations/delegations-index.service.ts (1 hunks)
Additional context used
Path-based instructions (1)
libs/auth-api-lib/src/lib/delegations/delegations-index.service.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
Biome
libs/auth-api-lib/src/lib/delegations/delegations-index.service.ts

[error] 143-143: Decorators are not valid here. (parse)

Decorators are only valid on class declarations, class expressions, and class methods.
You can enable parameter decorators by setting the unsafeParameterDecoratorsEnabled option to true in your configuration file.


[error] 145-145: Decorators are not valid here. (parse)

Decorators are only valid on class declarations, class expressions, and class methods.
You can enable parameter decorators by setting the unsafeParameterDecoratorsEnabled option to true in your configuration file.


[error] 147-147: Decorators are not valid here. (parse)

Decorators are only valid on class declarations, class expressions, and class methods.
You can enable parameter decorators by setting the unsafeParameterDecoratorsEnabled option to true in your configuration file.


[error] 223-224: Change to an optional chain. (lint/complexity/useOptionalChain)

Unsafe fix: Change to an optional chain.


[error] 464-464: Avoid the use of spread (...) syntax on accumulators. (lint/performance/noAccumulatingSpread)

Spread syntax should be avoided on accumulators (like those in .reduce) because it causes a time complexity of O(n^2).
Consider methods such as .splice or .push instead.

Additional comments not posted (1)
libs/auth-api-lib/src/lib/delegations/delegations-index.service.ts (1)

Line range hint 143-143: Check the usage of decorators.

The static analysis tool flagged potential issues with decorators. Please verify if decorators are used correctly in the context of this file, or if there's a misconfiguration in the analysis tool.

Also applies to: 145-145, 147-147

@kodiakhq kodiakhq bot merged commit 42ecb3f into main Jun 6, 2024
117 checks passed
@kodiakhq kodiakhq bot deleted the fix/delegation-index-primary-key-violation branch June 6, 2024 16:51
sigruntg pushed a commit that referenced this pull request Jun 12, 2024
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
lodmfjord pushed a commit that referenced this pull request Jun 14, 2024
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge Merge this PR as soon as all checks pass
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants