-
-
Notifications
You must be signed in to change notification settings - Fork 98
[REFACTOR] Avoid double lookups in keyed repo checks; trim names; clarify opened check in Nitrite.java #1163
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
…rify opened check in Nitrite.java
WalkthroughRefactors hasRepository overloads to avoid duplicate map lookups and null-pointer risk, by caching and null-checking the keyed repository set. Updates validateCollectionName to trim input before validation, using the normalized value for emptiness and reserved-name checks. No public API signatures changed; logic is confined to Changes
Sequence Diagram(s)sequenceDiagram
participant C as Caller
participant N as Nitrite
participant M as KeyedRepo Map
C->>N: hasRepository(Class/Decorator, key)
N->>N: map = listKeyedRepositories()
N->>M: set = map.get(key)
alt set is null
N-->>C: return false
else set contains entityName
N-->>C: return true
else not contained
N-->>C: return false
end
sequenceDiagram
participant C as Caller
participant N as Nitrite
C->>N: validateCollectionName(name)
N->>N: requireNonNull(name)
N->>N: trimmed = name.trim()
alt trimmed is empty or reserved
N-->>C: throw IllegalArgumentException
else valid
N-->>C: proceed
end
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related issues
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests
Tip 👮 Agentic pre-merge checks are now available in preview!Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.
Please see the documentation for more information. Example: reviews:
pre_merge_checks:
custom_checks:
- name: "Undocumented Breaking Changes"
mode: "warning"
instructions: |
Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).Please share your feedback with us on this Discord post. 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. Comment |
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 (3)
nitrite/src/main/java/org/dizitart/no2/Nitrite.java (3)
315-320: LGTM on single lookup; add explicit null-key guard to avoid possible NPE.This reduces lookups and reads well. To be defensive if
listKeyedRepositories()ever returns aConcurrentHashMap(or another Map impl that NPEs onget(null)), add a fast null-key guard.checkOpened(); - Map<String, Set<String>> keyed = listKeyedRepositories(); - Set<String> entities = keyed.get(key); + if (key == null) return false; + Map<String, Set<String>> keyed = listKeyedRepositories(); + Set<String> entities = keyed.get(key); if (entities == null) return false; String entityName = ObjectUtils.getEntityName(type); return entities.contains(entityName);
348-352: Guard nulls for consistency (decorator and key).Same perf/readability win here. Add a null check for
entityDecorator(aligns with other validation style) and a fast-return for nullkeyto prevent potential Map NPE.checkOpened(); - Map<String, Set<String>> keyed = listKeyedRepositories(); - Set<String> entities = keyed.get(key); - if (entities == null) return false; - return entities.contains(entityDecorator.getEntityName()); + notNull(entityDecorator, "entityDecorator cannot be null"); + if (key == null) return false; + Map<String, Set<String>> keyed = listKeyedRepositories(); + Set<String> entities = keyed.get(key); + if (entities == null) return false; + return entities.contains(entityDecorator.getEntityName());
362-365: Normalize collection names in lookup helpers (optional refactor)Trimming before validation is good — also trim/normalize inputs at lookup sites to avoid mismatches (e.g., default hasCollection uses listCollectionNames().contains(name)). See nitrite/src/main/java/org/dizitart/no2/Nitrite.java:285.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
nitrite/src/main/java/org/dizitart/no2/Nitrite.java(3 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). (1)
- GitHub Check: Codacy Static Code Analysis
|
@anidotnet Thanks for reviewing and approving. |
|
I have merged that |
@anidotnet I have refactored and tested all my changes as well. They passed.
Can you please review and merge?
Thanks
Summary by CodeRabbit
Bug Fixes
Refactor