Skip to content

Conversation

@hykim02
Copy link
Collaborator

@hykim02 hykim02 commented Apr 17, 2025

캐싱 전 후 성능 테스트 위해서 잠깐 보류합니다.

Summary by CodeRabbit

  • Chores

    • Internal improvements to dependency injection and field naming for better clarity and maintainability.
    • Adjusted caching behavior for cafeteria-related data; caching is currently disabled.
    • Updated access level for a shared utility to facilitate broader use across the application.
  • Refactor

    • Renamed several internal fields for improved code readability and consistency.

@coderabbitai
Copy link

coderabbitai bot commented Apr 17, 2025

Walkthrough

The changes introduce dependency injection of Jackson's ObjectMapper into several controller classes by adding it as an @Autowired field. Some import statements are updated to support this addition. In the CacheServiceV2 class, caching annotations are commented out, effectively disabling caching for certain methods. The DietServiceV2 class updates the names of its private fields for clarity and consistency. Additionally, the visibility of the objectMapper field in the JsonUtils utility class is changed from private to public, allowing direct access from other classes.

Changes

File(s) Change Summary
.../CafeteriaControllerV2.java Added imports for JsonProcessingException, ObjectMapper, and Autowired. No logic changes.
.../DietControllerV2.java, .../NoticeControllerV2.java Added private ObjectMapper objectMapper field with @Autowired injection. Minor import and whitespace adjustments.
.../CacheServiceV2.java Commented out @Cacheable annotations on two public methods, disabling caching functionality.
.../DietServiceV2.java Renamed two private final fields and updated all references to use new names.
.../JsonUtils.java Changed objectMapper field visibility from private to public.

Poem

In the warren of code, new beans now hop,
With ObjectMapper fields, the controllers won't stop.
Caching takes a nap, annotations asleep,
While variable names leap and boundaries creep.
Now JsonUtils shares its mapper with pride,
As rabbits in code, we bounce far and wide! 🐇

Tip

⚡💬 Agentic Chat (Pro Plan, General Availability)
  • We're introducing multi-step agentic chat in review comments and issue comments, within and outside of PR's. This feature enhances review and issue discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments and add commits to existing pull requests.
✨ 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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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.

Copy link

@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: 4

🧹 Nitpick comments (3)
src/main/java/com/example/Jinus/controller/v2/NoticeControllerV2.java (1)

38-38: Remove unnecessary blank line

This blank line appears to be an unintentional formatting change.

  public String responseDepartmentNotice(@RequestBody RequestDto requestDto) {
      String userId = requestDto.getUserRequest().getUser().getId();
-
      int departmentId = userServiceV2.getUserDepartmentId(userId);
src/main/java/com/example/Jinus/service/v2/cafeteria/CacheServiceV2.java (2)

21-26: Add context for disabled caching
The @Cacheable annotation block is commented out to run performance comparisons without caching. To avoid confusion later, please add a TODO (or similar) explaining the purpose of this change, linking to the performance test plan and indicating when caching should be re-enabled.


37-37: Add context for disabled caching
The single-line @Cacheable on getCafeteriaList is also commented out. Likewise, annotate this with a brief note (e.g., a TODO) so maintainers know it’s intentionally disabled for benchmarking and when to revert.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 32231b9 and a4eb0a9.

📒 Files selected for processing (6)
  • src/main/java/com/example/Jinus/controller/v2/CafeteriaControllerV2.java (2 hunks)
  • src/main/java/com/example/Jinus/controller/v2/DietControllerV2.java (2 hunks)
  • src/main/java/com/example/Jinus/controller/v2/NoticeControllerV2.java (3 hunks)
  • src/main/java/com/example/Jinus/service/v2/cafeteria/CacheServiceV2.java (2 hunks)
  • src/main/java/com/example/Jinus/service/v2/cafeteria/DietServiceV2.java (3 hunks)
  • src/main/java/com/example/Jinus/utility/JsonUtils.java (1 hunks)
🔇 Additional comments (4)
src/main/java/com/example/Jinus/service/v2/cafeteria/DietServiceV2.java (4)

23-24: Field renaming improves clarity
Renaming queryServiceV2cafeteriaQueryServiceV2 and parameterServiceV2dietParameterServiceV2 better reflects each service’s responsibility, enhancing readability and consistency.


34-34: Updated service reference
The call to dietParameterServiceV2.setParameters(...) correctly uses the renamed field. No further changes needed here.


42-42: Updated service reference
The invocation of cafeteriaQueryServiceV2.getCafeteriaId(...) aligns with the renamed field. This update is consistent and looks good.


57-57: Updated service reference
Updating to cafeteriaQueryServiceV2.getImgUrl(cafeteriaId) matches the field rename and preserves existing logic. Approved.


public class JsonUtils {
private static final ObjectMapper objectMapper = new ObjectMapper();
public static final ObjectMapper objectMapper = new ObjectMapper();
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider the implications of exposing ObjectMapper as public

Changing the visibility of the ObjectMapper from private to public exposes it for external modification and direct access. While this enables reuse across controllers, it introduces risks:

  1. External code could modify its configuration, leading to inconsistent behavior
  2. It creates two ways to handle JSON: via the utility method and direct access
  3. The static instance may have thread-safety concerns in certain scenarios

Consider whether the direct access is necessary, or if all JSON processing could be encapsulated through methods in JsonUtils.

If direct access is required, consider:

- public static final ObjectMapper objectMapper = new ObjectMapper();
+ // Create an immutable public instance with defense against modification
+ public static final ObjectMapper OBJECT_MAPPER = createObjectMapper();
+
+ private static ObjectMapper createObjectMapper() {
+     ObjectMapper mapper = new ObjectMapper();
+     mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
+     return mapper;
+ }

And remove the static block since initialization would happen in the createObjectMapper method.

Comment on lines +6 to +9
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Remove unused imports

The imports for JsonProcessingException, ObjectMapper, and Autowired are added but not used in this controller. Unlike other controllers, no ObjectMapper field is injected here.

This creates inconsistency with other controllers and clutters the code.

- import com.fasterxml.jackson.core.JsonProcessingException;
- import com.fasterxml.jackson.databind.ObjectMapper;
 import lombok.RequiredArgsConstructor;
- import org.springframework.beans.factory.annotation.Autowired;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import lombok.RequiredArgsConstructor;

Comment on lines +19 to +21
@Autowired
private ObjectMapper objectMapper;

Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Remove unused ObjectMapper and consider consistent DI style

The injected ObjectMapper is never used in this class, making it unnecessary. Additionally, the class mixes constructor injection (via @requiredargsconstructor) with field injection (@Autowired), which is inconsistent.

Spring best practices generally recommend constructor injection for required dependencies.

If the ObjectMapper is intended for future use, consider:

- @Autowired
- private ObjectMapper objectMapper;

If it will be needed later, add it through constructor injection instead:

private final ObjectMapper objectMapper;

// Update the class to use @AllArgsConstructor instead of @RequiredArgsConstructor
// or create an explicit constructor

Comment on lines +23 to +24
@Autowired
private ObjectMapper objectMapper;
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Remove unused ObjectMapper and consider consistent DI style

The injected ObjectMapper is never used in this class, making it unnecessary. Additionally, the class mixes constructor injection (via @requiredargsconstructor) with field injection (@Autowired), which is inconsistent.

Spring best practices generally recommend constructor injection for required dependencies.

If the ObjectMapper is intended for future use, consider:

- @Autowired
- private ObjectMapper objectMapper;

If it will be needed later, add it through constructor injection instead:

private final ObjectMapper objectMapper;

// Update the class to use @AllArgsConstructor instead of @RequiredArgsConstructor
// or create an explicit constructor

@hykim02 hykim02 merged commit daad2de into GNU-connect:main Apr 17, 2025
2 checks passed
@sentry
Copy link

sentry bot commented Apr 17, 2025

Suspect Issues

This pull request was deployed and Sentry observed the following issues:

  • ‼️ DataAccessResourceFailureException: Unable to acquire JDBC Connection [HikariPool-1 - Connection is not available, request timed out after 3476ms.] [n/a] POST /api/spring/v2/dish View Issue
  • ‼️ DataAccessResourceFailureException: Unable to acquire JDBC Connection [HikariPool-1 - Connection is not available, request timed out after 160875ms.] [n/a] POST /api/spring/v2/dish View Issue
  • ‼️ QueryTimeoutException: Redis command timed out POST /api/spring/v2/dish View Issue
  • ‼️ QueryTimeoutException: Redis command timed out POST /api/spring/v2/dish View Issue

Did you find this useful? React with a 👍 or 👎

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