Skip to content

[BEEEP][SM-1061] Add missing vault table indexes to EF config #63

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

lizard-boy
Copy link

@lizard-boy lizard-boy commented Oct 19, 2024

Type of change

- [ ] Bug fix
- [ ] New feature development
- [X] Tech debt (refactoring, code cleanup, dependency upgrades, etc)
- [ ] Build/deploy pipeline (DevOps)
- [ ] Other

Objective

The purpose of this PR is to add any missing indexes we have on Microsoft SQL Server configurations to the Entity Framework table configurations.

For this PR, I'll be excluding indexes that require custom filters because EF doesn't have a good way to handle them for multiple target database providers.

This was moved from bitwarden#2947 for just the vault tables.

Code changes

  • src/Infrastructure.EntityFramework/Repositories/DatabaseContext.cs:
    Extracting tables that required indexes into the IEntityTypeConfiguration and configuration folder approach.

  • src/Infrastructure.EntityFramework/Vault/Configurations/CipherEntityTypeConfiguration.cs:
    src/Infrastructure.EntityFramework/Vault/Configurations/FolderEntityTypeConfiguration.cs:
    Extracted into the IEntityTypeConfiguration and configuration folder approach.
    Adding missing indexes.

  • util/MySqlMigrations/Migrations/*:
    MySql EF migrations

  • util/PostgresMigrations/Migrations/*:
    Postgres EF migrations

  • util/SqliteMigrations/Migrations/*:
    Sqlite EF migrations

Before you submit

  • Please check for formatting errors (dotnet format --verify-no-changes) (required)
  • If making database changes - make sure you also update Entity Framework queries and/or migrations
  • Please add unit tests where it makes sense to do so (encouraged but not required)
  • If this change requires a documentation update - notify the documentation team
  • If this change has particular deployment requirements - notify the DevOps team

Greptile Summary

This pull request adds missing indexes to Entity Framework configurations for vault tables, focusing on improving query performance for Cipher and Folder entities across multiple database providers.

  • Added CipherEntityTypeConfiguration and FolderEntityTypeConfiguration classes to configure entity-specific indexes
  • Created new composite index on UserId and OrganizationId for Cipher table with included properties
  • Added separate indexes on OrganizationId, DeletedDate, and UserId for Cipher table
  • Implemented non-clustered index on UserId for Folder table with included properties
  • Generated migration files for MySQL, PostgreSQL, and SQLite to reflect these index changes

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

12 file(s) reviewed, 2 comment(s)
Edit PR Review Bot Settings | Greptile

Comment on lines +15 to +29
NpgsqlIndexBuilderExtensions.IncludeProperties(
builder.HasIndex(c => new { c.UserId, c.OrganizationId })
.IsClustered(false),
c =>
new
{
c.Type,
c.Data,
c.Favorites,
c.Folders,
c.Attachments,
c.CreationDate,
c.RevisionDate,
c.DeletedDate,
});
Copy link

Choose a reason for hiding this comment

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

logic: NpgsqlIndexBuilderExtensions is used, which may not be compatible with other database providers

Comment on lines +15 to +19
NpgsqlIndexBuilderExtensions.IncludeProperties(
builder.HasIndex(f => f.UserId)
.IsClustered(false),
f =>
new { f.Name, f.CreationDate, f.RevisionDate });
Copy link

Choose a reason for hiding this comment

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

logic: NpgsqlIndexBuilderExtensions is specific to PostgreSQL. This may cause issues with other database providers.

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