-
Notifications
You must be signed in to change notification settings - Fork 6
[NAE-2153] Mongo indexation #330
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
Conversation
Introduced the `@Indexed` annotation for marking fields as indexed. Enhanced the MongoDB runner to process both annotated and YAML-configured index definitions. Updated domain objects and configuration files to support index management.
Refactor MongoDB index management into a centralized configurator for better maintainability. Added @indexed annotation to various fields for automatic index resolution. Adjusted configurations and dependencies to support the new setup, consolidating indexing logic across the application.
Marking the CollectionNameProvider bean injection as @lazy prevents early initialization, potentially avoiding circular dependency issues. This ensures the application context loads more efficiently and resolves dependencies dynamically when needed.
|
Warning Rate limit exceeded@renczesstefan has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 1 minutes and 21 seconds before requesting another review. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the 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. 📒 Files selected for processing (2)
WalkthroughThis change introduces a new infrastructure for MongoDB index configuration and management. It adds a custom Changes
Sequence Diagram(s)sequenceDiagram
participant RealmServiceImpl
participant CollectionNameProvider
participant MongoTemplate
participant MongoIndexesConfigurator
RealmServiceImpl->>CollectionNameProvider: getCollectionName(realm)
RealmServiceImpl->>MongoTemplate: collectionExists(collectionName)
alt Collection does not exist
RealmServiceImpl->>MongoTemplate: createCollection(collectionName)
RealmServiceImpl->>MongoIndexesConfigurator: resolveIndexes(collectionName, User.class)
end
RealmServiceImpl-->>RealmServiceImpl: return saved realm
sequenceDiagram
participant MongoDbRunner
participant MongoIndexesConfigurator
MongoDbRunner->>MongoIndexesConfigurator: resolveIndexes()
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~18 minutes Suggested labels
✨ Finishing Touches
🧪 Generate unit tests
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 7
🧹 Nitpick comments (4)
application-engine/src/main/java/com/netgrif/application/engine/startup/runner/MongoDbRunner.java (1)
43-44: Remove unnecessary empty lines.Clean up the trailing empty lines for better code formatting.
- -application-engine/src/main/java/com/netgrif/application/engine/configuration/MongoIndexesConfigurator.java (1)
9-11: Remove unused @slf4j annotationThe
@Slf4jannotation creates a logger that is not used in this class.-@Slf4j @Component public class MongoIndexesConfigurator extends com.netgrif.application.engine.adapter.spring.configuration.MongoIndexesConfigurator {nae-spring-core-adapter/src/main/java/com/netgrif/application/engine/adapter/spring/configuration/MongoIndexesConfigurator.java (2)
33-33: Add JavaDoc for abstract methodThe abstract
getIndexes()method should have documentation explaining its purpose and expected return value structure.+ /** + * Returns a mapping of entity classes to their additional index field names. + * Implementations should provide indexes that are configured externally + * (e.g., through application properties) rather than via annotations. + * + * @return MultiValueMap where keys are entity classes and values are field names to index + */ public abstract MultiValueMap<Class<?>, String> getIndexes();
35-49: Consider caching index definitions for performanceThe index resolution performs reflection operations on every call. For better performance, consider caching the resolved index definitions per entity type, especially if this method is called frequently.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (15)
application-engine/pom.xml(0 hunks)application-engine/src/main/java/com/netgrif/application/engine/configuration/MongoIndexesConfigurator.java(1 hunks)application-engine/src/main/java/com/netgrif/application/engine/configuration/properties/DataConfigurationProperties.java(2 hunks)application-engine/src/main/java/com/netgrif/application/engine/startup/runner/MongoDbRunner.java(3 hunks)nae-object-library/src/main/java/com/netgrif/application/engine/objects/annotations/Indexed.java(1 hunks)nae-object-library/src/main/java/com/netgrif/application/engine/objects/auth/domain/User.java(2 hunks)nae-object-library/src/main/java/com/netgrif/application/engine/objects/workflow/domain/Case.java(4 hunks)nae-object-library/src/main/java/com/netgrif/application/engine/objects/workflow/domain/Task.java(3 hunks)nae-spring-core-adapter/pom.xml(1 hunks)nae-spring-core-adapter/src/main/java/com/netgrif/application/engine/adapter/spring/auth/domain/User.java(1 hunks)nae-spring-core-adapter/src/main/java/com/netgrif/application/engine/adapter/spring/configuration/MongoIndexesConfigurator.java(1 hunks)nae-spring-core-adapter/src/main/java/com/netgrif/application/engine/adapter/spring/petrinet/domain/PetriNet.java(1 hunks)nae-spring-core-adapter/src/main/java/com/netgrif/application/engine/adapter/spring/workflow/domain/Case.java(1 hunks)nae-spring-core-adapter/src/main/java/com/netgrif/application/engine/adapter/spring/workflow/domain/Task.java(1 hunks)nae-user-ce/src/main/java/com/netgrif/application/engine/auth/service/RealmServiceImpl.java(4 hunks)
💤 Files with no reviewable changes (1)
- application-engine/pom.xml
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
- GitHub Check: task-list-completed
- GitHub Check: task-list-completed
- GitHub Check: task-list-completed
- GitHub Check: task-list-completed
- GitHub Check: Build
- GitHub Check: task-list-completed
🔇 Additional comments (23)
nae-object-library/src/main/java/com/netgrif/application/engine/objects/annotations/Indexed.java (1)
8-11: Well-designed marker annotation for MongoDB indexing.The annotation follows best practices with appropriate retention policy (RUNTIME) for reflection-based processing and correct target limitation (FIELD). The simple marker design is suitable for the MongoDB indexing use case.
nae-spring-core-adapter/src/main/java/com/netgrif/application/engine/adapter/spring/auth/domain/User.java (2)
12-12: LGTM - Import statement correctly added.The import for Spring Data MongoDB's @document annotation is properly placed.
16-16: LGTM - @document annotation properly applied.The @document annotation correctly marks this User class as a MongoDB document entity, enabling it to be discovered by the new MongoIndexesConfigurator for index management.
nae-spring-core-adapter/src/main/java/com/netgrif/application/engine/adapter/spring/workflow/domain/Task.java (2)
19-19: LGTM - Import statement correctly added.The import for Spring Data MongoDB's @document annotation is properly placed.
24-24: LGTM - @document annotation properly applied.The @document annotation correctly marks this Task class as a MongoDB document entity, enabling index management through the MongoIndexesConfigurator infrastructure.
nae-spring-core-adapter/src/main/java/com/netgrif/application/engine/adapter/spring/workflow/domain/Case.java (1)
20-20: LGTM - @document annotation properly applied.The @document annotation correctly marks this Case class as a MongoDB document entity.
nae-spring-core-adapter/src/main/java/com/netgrif/application/engine/adapter/spring/petrinet/domain/PetriNet.java (1)
11-11: LGTM! Proper MongoDB document annotation added.The addition of the
@Documentannotation correctly marks this class as a MongoDB document entity, enabling it to participate in the new MongoDB indexing framework.Also applies to: 16-16
application-engine/src/main/java/com/netgrif/application/engine/configuration/properties/DataConfigurationProperties.java (2)
14-15: LGTM! Appropriate imports added for the new indexes property.The imports for
LinkedMultiValueMapandMultiValueMapsupport the new indexes configuration functionality.Also applies to: 18-18
139-146: LGTM! Well-designed indexes property for MongoDB configuration.The
MultiValueMap<Class<?>, String>type is appropriate for storing multiple index definitions per entity class. The comprehensive Javadoc documentation clearly explains the purpose and usage of this property.nae-object-library/src/main/java/com/netgrif/application/engine/objects/workflow/domain/Case.java (4)
4-4: LGTM! Proper import for the indexing annotation.The import for the custom
@Indexedannotation enables marking fields for MongoDB index creation.
42-43: LGTM! Appropriate indexing on petriNetObjectId field.Indexing the
petriNetObjectIdfield is sensible as it's frequently used to query cases by their associated Petri net process.
59-60: LGTM! Proper indexing on title field.The
titlefield is commonly used for searching and filtering cases, making it an appropriate candidate for indexing.
82-83: LGTM! Logical indexing on author field.Indexing the
authorfield enables efficient filtering of cases by their creator, which is a common query pattern.application-engine/src/main/java/com/netgrif/application/engine/startup/runner/MongoDbRunner.java (2)
3-3: LGTM! Proper dependency injection for MongoDB index configuration.The addition of
MongoIndexesConfiguratoras a dependency correctly enables delegation of index resolution to the dedicated component.Also applies to: 27-27
38-40: LGTM! Proper delegation to the index configurator.The refactoring correctly delegates index resolution to the
MongoIndexesConfigurator, improving separation of concerns and centralizing index management logic.nae-object-library/src/main/java/com/netgrif/application/engine/objects/workflow/domain/Task.java (5)
4-4: LGTM! Proper import for the indexing annotation.The import for the custom
@Indexedannotation enables marking fields for MongoDB index creation.
36-37: LGTM! Appropriate indexing on processId field.The
processIdfield is frequently used to query tasks by their associated process, making it an excellent candidate for indexing.
41-42: LGTM! Proper indexing on caseId field.Indexing the
caseIdfield enables efficient retrieval of tasks associated with specific cases, which is a common query pattern.
46-47: LGTM! Logical indexing on transitionId field.The
transitionIdfield is used to identify tasks by their workflow transition, making indexing beneficial for task filtering and retrieval.
70-71: LGTM! Essential indexing on userId field.Indexing the
userIdfield is crucial for efficiently querying tasks assigned to specific users, which is one of the most common task retrieval patterns.application-engine/src/main/java/com/netgrif/application/engine/configuration/MongoIndexesConfigurator.java (1)
15-25: LGTM! Clean implementation of the configurator patternThe class properly extends the abstract configurator and delegates index configuration to properties. The constructor correctly passes dependencies to the superclass.
nae-user-ce/src/main/java/com/netgrif/application/engine/auth/service/RealmServiceImpl.java (1)
49-53: Clarify the need for @lazy annotationThe
@Lazyannotation onsetCollectionNameProvidersuggests a potential circular dependency. Consider documenting why lazy initialization is required here or refactoring to avoid circular dependencies.nae-object-library/src/main/java/com/netgrif/application/engine/objects/auth/domain/User.java (1)
30-52: LGTM! Appropriate fields selected for indexingThe indexed fields (username, email, firstName, middleName, lastName) are commonly used in user queries and searches. This indexing strategy will improve query performance for typical user lookup operations.
...cation-engine/src/main/java/com/netgrif/application/engine/startup/runner/MongoDbRunner.java
Outdated
Show resolved
Hide resolved
...va/com/netgrif/application/engine/adapter/spring/configuration/MongoIndexesConfigurator.java
Show resolved
Hide resolved
...va/com/netgrif/application/engine/adapter/spring/configuration/MongoIndexesConfigurator.java
Show resolved
Hide resolved
...dapter/src/main/java/com/netgrif/application/engine/adapter/spring/workflow/domain/Case.java
Outdated
Show resolved
Hide resolved
...dapter/src/main/java/com/netgrif/application/engine/adapter/spring/workflow/domain/Case.java
Outdated
Show resolved
Hide resolved
nae-user-ce/src/main/java/com/netgrif/application/engine/auth/service/RealmServiceImpl.java
Show resolved
Hide resolved
...ine/src/main/java/com/netgrif/application/engine/configuration/MongoIndexesConfigurator.java
Outdated
Show resolved
Hide resolved
...dapter/src/main/java/com/netgrif/application/engine/adapter/spring/workflow/domain/Case.java
Outdated
Show resolved
Hide resolved
# Conflicts: # nae-object-library/src/main/java/com/netgrif/application/engine/objects/auth/domain/User.java # nae-object-library/src/main/java/com/netgrif/application/engine/objects/workflow/domain/Case.java # nae-object-library/src/main/java/com/netgrif/application/engine/objects/workflow/domain/Task.java # nae-spring-core-adapter/src/main/java/com/netgrif/application/engine/adapter/spring/auth/domain/User.java
Renamed the base class to better reflect its abstract nature and purpose. Updated all references across the codebase to ensure consistency and removed an unused field from the Case class. This improves clarity and eliminates unnecessary elements.
Modified `resolveIndexes` to only process collections annotated with `@Document`. This ensures index definitions are applied correctly and avoids unnecessary operations on non-annotated collections. Added a safeguard using `ArrayList` to manage index definitions.
There was a problem hiding this 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)
nae-spring-core-adapter/src/main/java/com/netgrif/application/engine/adapter/spring/configuration/AbstractMongoIndexesConfigurator.java (1)
57-57: Remove extra semicolon.- Iterable<Field> additionalIndexedProperties = FieldUtils.getFieldsListWithAnnotation(collectionType, Indexed.class);; + Iterable<Field> additionalIndexedProperties = FieldUtils.getFieldsListWithAnnotation(collectionType, Indexed.class);
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
nae-spring-core-adapter/src/main/java/com/netgrif/application/engine/adapter/spring/configuration/AbstractMongoIndexesConfigurator.java(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
- GitHub Check: task-list-completed
- GitHub Check: task-list-completed
- GitHub Check: Build
🔇 Additional comments (3)
nae-spring-core-adapter/src/main/java/com/netgrif/application/engine/adapter/spring/configuration/AbstractMongoIndexesConfigurator.java (3)
28-32: Constructor initialization looks good.Proper initialization of the mapping context and index resolver from the MongoTemplate.
36-41: Efficient processing of all document entities.Good use of streams and proper filtering for @document annotated entities.
69-75: Clean implementation of configured field indexing.Good use of MultiValueMap and proper null-safety check.
...etgrif/application/engine/adapter/spring/configuration/AbstractMongoIndexesConfigurator.java
Outdated
Show resolved
Hide resolved
Replaced the use of `collectionName` with `collectionType` to fetch the `@Document` annotation. This ensures that index definitions are properly resolved for the correct collection type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
nae-spring-core-adapter/src/main/java/com/netgrif/application/engine/adapter/spring/configuration/AbstractMongoIndexesConfigurator.java (1)
57-57: Remove the extra semicolon.There's an unnecessary extra semicolon at the end of the line.
- Iterable<Field> additionalIndexedProperties = FieldUtils.getFieldsListWithAnnotation(collectionType, Indexed.class);; + Iterable<Field> additionalIndexedProperties = FieldUtils.getFieldsListWithAnnotation(collectionType, Indexed.class);
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
nae-spring-core-adapter/src/main/java/com/netgrif/application/engine/adapter/spring/configuration/AbstractMongoIndexesConfigurator.java(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
- GitHub Check: Test
- GitHub Check: task-list-completed
- GitHub Check: task-list-completed
- GitHub Check: task-list-completed
- GitHub Check: task-list-completed
- GitHub Check: task-list-completed
🔇 Additional comments (6)
nae-spring-core-adapter/src/main/java/com/netgrif/application/engine/adapter/spring/configuration/AbstractMongoIndexesConfigurator.java (6)
1-20: LGTM!The package declaration and imports are well-organized and appropriate for the MongoDB index configuration functionality.
21-32: LGTM!Clean design with proper dependency injection and immutable fields. The constructor correctly initializes the mapping context and index resolver from the MongoTemplate.
34-34: LGTM!Good abstraction design using MultiValueMap to allow multiple index field names per entity class.
36-41: LGTM!Properly filters MongoDB document entities and delegates to the specific index resolution method. Stream usage is appropriate and efficient.
43-54: LGTM!The method correctly combines index definitions from all three sources (Spring Data annotations, custom @indexed annotations, and configuration). The critical annotation lookup issue identified in the previous review has been properly fixed.
56-76: LGTM!Both helper methods correctly handle their respective index sources. The code properly respects Spring Data's @field annotation for custom field names and maintains a consistent index creation pattern.
Unused imports were cleaned up to maintain code clarity and readability. The log message was corrected to reference `mongoProperties.getDatabase()` instead of an undefined `name`, ensuring accurate database information is logged.
Enclose collection creation in a try-catch block to handle potential errors. Log the error, clean up by deleting the realm, and rethrow a runtime exception. This ensures better error handling and prevents inconsistent state.
Introduced a new method `getEntityIndexBlacklist` to allow specifying entities to exclude from index creation. Updated the `resolveIndexes` method to respect the blacklist when determining which entities to process.
Description
Implements NAE-2153
Dependencies
Third party dependencies
Dependency
was moved from
application-enginemodule tonae-spring-core-adaptermodule.Blocking Pull requests
There are no dependencies on other PR
How Has Been This Tested?
This was tested manually and with unit tests.
Test Configuration
Checklist:
Summary by CodeRabbit
New Features
Improvements
Dependency Updates