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

feat: Add reverse indexes on Localizations and SearchTags #1971

Merged

Conversation

oskogstad
Copy link
Collaborator

@oskogstad oskogstad commented Feb 26, 2025

Description

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)

Co-authored-by: Bjørn Dybvik Langfors [email protected]
Co-authored-by: Magnus Sandgren [email protected]

Copy link
Contributor

coderabbitai bot commented Feb 26, 2025

Warning

Rate limit exceeded

@oskogstad has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 17 minutes and 46 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 6a4eb46 and a164a87.

⛔ Files ignored due to path filters (2)
  • src/Digdir.Domain.Dialogporten.Infrastructure/Persistence/Migrations/20250226145405_CreateGinIndexOnLocalizationsAndSearchTags.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 (8)
  • src/Digdir.Domain.Dialogporten.Infrastructure/Persistence/Configurations/Dialogs/DialogEntityConfiguration.cs (2 hunks)
  • src/Digdir.Domain.Dialogporten.Infrastructure/Persistence/Configurations/Dialogs/DialogSearchTagConfiguration.cs (1 hunks)
  • src/Digdir.Domain.Dialogporten.Infrastructure/Persistence/Configurations/Localizations/LocalizationConfiguration.cs (1 hunks)
  • src/Digdir.Domain.Dialogporten.Infrastructure/Persistence/Constants.cs (1 hunks)
  • src/Digdir.Domain.Dialogporten.Infrastructure/Persistence/DialogDbContext.cs (2 hunks)
  • src/Digdir.Domain.Dialogporten.Infrastructure/Persistence/IdempotentNotifications/NotificationAcknowledgement.cs (2 hunks)
  • src/Digdir.Domain.Dialogporten.Infrastructure/Persistence/Interceptors/ConvertDomainEventsToOutboxMessagesInterceptor.cs (1 hunks)
  • src/Digdir.Domain.Dialogporten.Infrastructure/Persistence/Migrations/20250226145405_CreateGinIndexOnLocalizationsAndSearchTags.cs (1 hunks)
📝 Walkthrough

Walkthrough

The changes standardize the usage of constants by replacing fully qualified and aliased references with direct static imports. Multiple configuration files now use a new internal Constants class for centralized PostgreSQL indexing values, and new GIN index configurations have been added for improved search performance on specific columns. The database context has been updated to explicitly qualify domain constants and include the PostgreSQL trigram extension, while a new migration facilitates index creation. The overall functionality remains unchanged.

Changes

File(s) Changes Summary
src/.../Configurations/Dialogs/DialogEntityConfiguration.cs, src/.../IdempotentNotifications/NotificationAcknowledgement.cs Replaced fully qualified constant references with direct static member usage and removed redundant using directives.
src/.../Configurations/Dialogs/DialogSearchTagConfiguration.cs, src/.../Configurations/Localizations/LocalizationConfiguration.cs Updated property configurations to use static constant imports and introduced new GIN index configurations with trigram operators for the Value property.
src/.../DialogDbContext.cs, src/.../Migrations/20250226142844_CreateGinIndexOnLocalizationsAndSearchTags.cs Qualified domain constant references in DbContext; added the PostgreSQL trigram extension and a migration to create GIN indexes for optimized search operations.
src/.../Constants.cs, src/.../Interceptors/ConvertDomainEventsToOutboxMessagesInterceptor.cs Added a new internal Constants class for PostgreSQL indexing values and removed aliasing in the interceptor to directly use GraphQlSubscriptionConstants.

Possibly related PRs

  • feat: Add idempotentId #1638: Introduces an idempotency feature (IdempotentId/IdempotentKey) in dialog creation, which directly relates to similar idempotency handling changes in this PR.

Suggested reviewers

  • MagnusSandgren

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>, 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 changed the title feat(app): Add reverse indexes on Localizations and SearchTags feat: Add reverse indexes on Localizations and SearchTags Feb 26, 2025
@oskogstad oskogstad force-pushed the feat/add-reverse-indexes-for-localizations-and-searchtags branch 3 times, most recently from 37cb74b to 5a6f96c Compare February 26, 2025 14:32
@oskogstad oskogstad marked this pull request as ready for review February 26, 2025 14:44
@oskogstad oskogstad requested a review from a team as a code owner February 26, 2025 14:44
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

🧹 Nitpick comments (1)
src/Digdir.Domain.Dialogporten.Infrastructure/Persistence/Migrations/20250226142844_CreateGinIndexOnLocalizationsAndSearchTags.cs (1)

13-14: Consider centralizing PostgreSQL extension annotation

The string literal for the PostgreSQL extension annotation could be replaced with a constant from the new Constants class for better maintainability.

migrationBuilder.AlterDatabase()
-    .Annotation("Npgsql:PostgresExtension:pg_trgm", ",,");
+    .Annotation(Constants.PostgreSqlExtensionPrefix + Constants.PostrgreSqlTrigram, ",,");
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 84a3fc6 and 6a4eb46.

⛔ Files ignored due to path filters (2)
  • src/Digdir.Domain.Dialogporten.Infrastructure/Persistence/Migrations/20250226142844_CreateGinIndexOnLocalizationsAndSearchTags.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 (8)
  • src/Digdir.Domain.Dialogporten.Infrastructure/Persistence/Configurations/Dialogs/DialogEntityConfiguration.cs (2 hunks)
  • src/Digdir.Domain.Dialogporten.Infrastructure/Persistence/Configurations/Dialogs/DialogSearchTagConfiguration.cs (2 hunks)
  • src/Digdir.Domain.Dialogporten.Infrastructure/Persistence/Configurations/Localizations/LocalizationConfiguration.cs (1 hunks)
  • src/Digdir.Domain.Dialogporten.Infrastructure/Persistence/Constants.cs (1 hunks)
  • src/Digdir.Domain.Dialogporten.Infrastructure/Persistence/DialogDbContext.cs (2 hunks)
  • src/Digdir.Domain.Dialogporten.Infrastructure/Persistence/IdempotentNotifications/NotificationAcknowledgement.cs (2 hunks)
  • src/Digdir.Domain.Dialogporten.Infrastructure/Persistence/Interceptors/ConvertDomainEventsToOutboxMessagesInterceptor.cs (1 hunks)
  • src/Digdir.Domain.Dialogporten.Infrastructure/Persistence/Migrations/20250226142844_CreateGinIndexOnLocalizationsAndSearchTags.cs (1 hunks)
✅ Files skipped from review due to trivial changes (2)
  • src/Digdir.Domain.Dialogporten.Infrastructure/Persistence/Interceptors/ConvertDomainEventsToOutboxMessagesInterceptor.cs
  • src/Digdir.Domain.Dialogporten.Infrastructure/Persistence/Constants.cs
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: Dry run deploy apps / Deploy service to test
  • GitHub Check: Dry run deploy apps / Deploy graphql to test
  • GitHub Check: Dry run deploy apps / Deploy web-api-so to test
  • GitHub Check: Dry run deploy apps / Deploy web-api-eu to test
  • GitHub Check: build / build-and-test
🔇 Additional comments (12)
src/Digdir.Domain.Dialogporten.Infrastructure/Persistence/Configurations/Localizations/LocalizationConfiguration.cs (1)

14-18: Well-implemented text search optimization.

The addition of a GIN index with trigram operators on the Value property is an excellent approach for enhancing text search capabilities on localization values. This will significantly improve performance for partial and fuzzy text searches, which is particularly valuable for localized content.

src/Digdir.Domain.Dialogporten.Infrastructure/Persistence/IdempotentNotifications/NotificationAcknowledgement.cs (2)

4-4: Good coding style improvement.

Using static imports for constants makes the code cleaner and easier to read.


21-21: Consistent use of direct constant reference.

The direct reference to DefaultMaxStringLength without the Constants. prefix improves readability while maintaining the same functionality.

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

4-4: Good coding style improvement.

Using static imports for constants makes the code cleaner and easier to read.


14-14: Consistent use of direct constant reference.

The direct reference to DefaultMaxStringLength without the Constants. prefix improves readability while maintaining the same functionality.

src/Digdir.Domain.Dialogporten.Infrastructure/Persistence/Configurations/Dialogs/DialogSearchTagConfiguration.cs (3)

4-4: Good coding style improvement.

Using static imports for constants makes the code cleaner and easier to read.


15-15: Consistent use of direct constant reference.

The direct reference to MaxSearchTagLength without the Constants. prefix improves readability while maintaining the same functionality.


17-19: Well-implemented text search optimization.

The addition of a GIN index with trigram operators on the Value property is an excellent approach for enhancing text search capabilities on search tags. This will significantly improve performance for partial and fuzzy text searches, which is crucial for search functionality.

Note that while you're using static imports for domain constants, Constants.Gin and Constants.GinTrgmOps are still fully qualified, suggesting they come from a different Constants class than the one being statically imported.

src/Digdir.Domain.Dialogporten.Infrastructure/Persistence/Migrations/20250226142844_CreateGinIndexOnLocalizationsAndSearchTags.cs (2)

1-46: GIN indexes implemented correctly for improved search performance

The migration properly creates GIN indexes with trigram operations on the Value columns of both Localization and DialogSearchTag tables, and adds the required PostgreSQL trigram extension. This will significantly improve text search performance, especially for queries using LIKE operations or fuzzy matching.

The Up and Down methods are correctly implemented to allow bidirectional migration.


14-14:

❓ Verification inconclusive

Verify the empty parameters in the extension annotation

The extension annotation has empty parameters (",,"). Is this intentional? Consider documenting the purpose of these empty parameters or adjusting if necessary.


🏁 Script executed:

#!/bin/bash
# Check how postgres extension annotations are implemented in other migrations
rg -A 2 "PostgresExtension" --glob="*.cs" --glob="!*20250226142844_*"

Length of output: 452


Clarify Usage of Empty Parameters in Extension Annotation

The migration file uses an annotation with empty parameters:

.Annotation("Npgsql:PostgresExtension:pg_trgm", ",,");

This contrasts with other parts of the code (e.g., in DialogDbContext.cs where the extension is added via .HasPostgresExtension(Constants.PostrgreSqlTrigram)). Please verify that the empty parameter string is intentional. If so, adding a comment explaining the design decision would help future maintainers; otherwise, consider aligning this implementation with the pattern used elsewhere.

src/Digdir.Domain.Dialogporten.Infrastructure/Persistence/DialogDbContext.cs (2)

103-104: Improved clarity with fully qualified constant references

Explicitly qualifying the constants with their namespace improves code clarity and prevents ambiguity when multiple Constants classes exist.


115-117: Extension registration aligns with migration changes

Adding the PostgreSQL trigram extension registration in the DbContext ensures consistency with the migration that creates the GIN indexes. This is a good practice that keeps the model definition aligned with the actual database state.

@oskogstad oskogstad force-pushed the feat/add-reverse-indexes-for-localizations-and-searchtags branch from 6a4eb46 to 390f105 Compare February 26, 2025 14:55
@MagnusSandgren MagnusSandgren self-requested a review February 28, 2025 07:40
Copy link
Collaborator

@MagnusSandgren MagnusSandgren left a comment

Choose a reason for hiding this comment

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

Dette blir spennende!

@oskogstad oskogstad merged commit 7a506b3 into main Feb 28, 2025
25 checks passed
@oskogstad oskogstad deleted the feat/add-reverse-indexes-for-localizations-and-searchtags branch February 28, 2025 11:45
oskogstad pushed a commit that referenced this pull request Feb 28, 2025
🤖 I have created a release *beep* *boop*
---


##
[1.57.0](v1.56.1...v1.57.0)
(2025-02-28)


### Features

* Add reverse indexes on Localizations and SearchTags
([#1971](#1971))
([7a506b3](7a506b3))
* **ci:** Enable PostreSQL extension pg_trgm
([#1984](#1984))
([4dce375](4dce375))


### Miscellaneous Chores

* **sdk:** Add doc
([#1975](#1975))
([37c9130](37c9130))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).
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.

2 participants