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(db): Add missing indexes for search #2015

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

oskogstad
Copy link
Collaborator

@oskogstad oskogstad commented Mar 5, 2025

Description

Adding indexes for dialog

  • Deleted
  • ExtendedStatus
  • ExtendedReference
  • VisibleFrom

Related Issue(s)

Verification

  • Your code builds clean without any errors or warnings
  • Manual testing done (required)
  • Relevant automated test added (if you find this hard, leave it and we'll help out)

Documentation

  • Documentation is updated (either in docs-directory, Altinnpedia or a separate linked PR in altinn-studio-docs., if applicable)

@oskogstad oskogstad requested a review from a team as a code owner March 5, 2025 16:55
Copy link
Contributor

coderabbitai bot commented Mar 5, 2025

📝 Walkthrough

Walkthrough

This pull request enhances database indexing and collation settings for dialog and soft deletable entities. The changes update the dialog entity configuration with new indexes and enforce case-sensitive string comparisons by setting collation "C". A new migration is added to create and drop specific indexes on the dialog table, and an index is introduced on the soft deletion field to improve query performance.

Changes

Files Change Summary
src/Digdir.Domain.Dialogporten.Infrastructure/…/DialogEntityConfiguration.cs
src/Digdir.Domain.Dialogporten.Infrastructure/…/20250305165700_AddMissingSearchIndexesExtStatusExtRefDeleted.cs
Reorganized dialog entity indexing: added new indexes for properties such as ServiceResource, Party, Org, VisibleFrom, ExtendedStatus, ExternalReference, and Deleted; updated collation to "C" for string properties; restructured the IdempotentKey configuration; introduced a migration with Up/Down methods to manage these indexes.
src/Digdir.Library.Entity.EntityFrameworkCore/…/SoftDeletableExtensions.cs Added an index on the Deleted property within the soft deletable query filter for optimized queries on soft-deleted entities.

Possibly related PRs

  • feat: Add idempotentId #1638: Addresses the handling of the IdempotentKey property in the dialog entity, which is directly connected to the changes made in this PR.

Suggested reviewers

  • MagnusSandgren
✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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 using 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 generate docstrings to generate docstrings for this 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.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

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.

@oskogstad oskogstad force-pushed the fix/add-missing-indexes-for-search branch from 9ca1ce5 to 35f4f14 Compare March 5, 2025 16:57
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

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f8d232b and 35f4f14.

⛔ Files ignored due to path filters (2)
  • src/Digdir.Domain.Dialogporten.Infrastructure/Persistence/Migrations/20250305165700_AddMissingSearchIndexesExtStatusExtRefDeleted.Designer.cs is excluded by !**/Migrations/**/*Designer.cs
  • src/Digdir.Domain.Dialogporten.Infrastructure/Persistence/Migrations/DialogDbContextModelSnapshot.cs is excluded by !**/Migrations/DialogDbContextModelSnapshot.cs
📒 Files selected for processing (3)
  • src/Digdir.Domain.Dialogporten.Infrastructure/Persistence/Configurations/Dialogs/DialogEntityConfiguration.cs (1 hunks)
  • src/Digdir.Domain.Dialogporten.Infrastructure/Persistence/Migrations/20250305165700_AddMissingSearchIndexesExtStatusExtRefDeleted.cs (1 hunks)
  • src/Digdir.Library.Entity.EntityFrameworkCore/Features/SoftDeletable/SoftDeletableExtensions.cs (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Dry run deploy apps / Deploy migration job to test
  • GitHub Check: build / build-and-test
🔇 Additional comments (10)
src/Digdir.Library.Entity.EntityFrameworkCore/Features/SoftDeletable/SoftDeletableExtensions.cs (1)

90-91: Good enhancement: Adding index on Deleted field improves query performance.

Adding an index on the Deleted property for all soft-deletable entities is a valuable improvement. This will significantly optimize query performance when filtering out soft-deleted records, which is a common operation since the query filter x => !x.Deleted is applied to all soft-deletable entities.

src/Digdir.Domain.Dialogporten.Infrastructure/Persistence/Migrations/20250305165700_AddMissingSearchIndexesExtStatusExtRefDeleted.cs (3)

7-9: Migration class name accurately reflects its purpose.

The class name AddMissingSearchIndexesExtStatusExtRefDeleted clearly indicates the purpose of adding indexes for ExtendedStatus, ExternalReference, and Deleted fields, which aligns with the PR objectives.


13-32: Well-structured index creation for improved search performance.

These four indexes on Deleted, ExtendedStatus, ExternalReference, and VisibleFrom columns will improve query performance for dialog search operations. The migration correctly creates each index with appropriate naming conventions.


37-51: Proper implementation of Down method for reversibility.

The Down method properly drops all created indexes in the reverse order, ensuring clean migration rollback if needed.

src/Digdir.Domain.Dialogporten.Infrastructure/Persistence/Configurations/Dialogs/DialogEntityConfiguration.cs (6)

14-18: Good index addition and collation setting for ServiceResource.

Adding an index on ServiceResource and setting case-sensitive collation with "C" will improve search performance and ensure proper string comparison behavior.


20-22: Enhanced indexing and case-sensitive comparison for Party field.

Adding an index on the Party field and setting case-sensitive collation will improve query performance when filtering by party.


24-30: Well-designed indexing strategy for organizational uniqueness.

Good implementation of:

  1. A simple index on Org for regular filtering
  2. A composite unique index on {Org, IdempotentKey} with a null filter
  3. Case-sensitive collation for the Org field

This approach ensures both efficient querying and proper enforcement of business constraints.


31-32: Appropriate length constraint for IdempotentKey.

Setting the maximum length of IdempotentKey to 36 characters is appropriate for storing UUID/GUID values.


36-37: Temporal field indexing enhances date-based filtering.

Adding indexes on both DueAt and VisibleFrom will improve performance for date range queries and filtering dialog records based on temporal constraints.


39-40: Search performance improvement for extended fields.

Adding indexes on ExtendedStatus and ExternalReference fields will enhance search performance when filtering dialogs based on these attributes, which aligns with the PR objectives.

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