Skip to content

872: Migrate BackgroundTask to use Optional#908

Merged
luoh00 merged 2 commits into
mainfrom
872
Apr 23, 2026
Merged

872: Migrate BackgroundTask to use Optional#908
luoh00 merged 2 commits into
mainfrom
872

Conversation

@luoh00

@luoh00 luoh00 commented Apr 17, 2026

Copy link
Copy Markdown
Contributor

872

Description of changes

Migrated from using null to using Optional for BackgroundTask and related files

Checklist before review

  • I have done a thorough self-review of the PR
  • Copilot has reviewed my latest changes, and all comments have been fixed and/or closed.
  • If I have made database changes, I have made sure I followed all the db repo rules listed in the wiki here. (check if no db changes)
  • All tests have passed
  • I have successfully deployed this PR to staging
  • I have done manual QA in both dev (and staging if possible) and attached screenshots below.

Screenshots

Dev

n/a

Staging

n/a

@github-actions

Copy link
Copy Markdown
Contributor

Available PR Commands

  • /ai - Triggers all AI review commands at once
  • /review - AI review of the PR changes
  • /describe - AI-powered description of the PR
  • /improve - AI-powered suggestions
  • /deploy - Deploy to staging

See: https://github.com/tahminator/codebloom/wiki/CI-Commands

@luoh00 luoh00 changed the title 872 872: Migrate BackgroundTask to use Optional Apr 17, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Title

872


PR Type

Enhancement


Description

  • Update BackgroundTaskRepository methods to return Optional.

  • Implement Optional return types in BackgroundTaskSqlRepository.

  • Adapt scheduled tasks to consume Optional results.

  • Refactor unit tests to validate Optional handling.


Diagram Walkthrough

flowchart LR
  A[BackgroundTaskRepository] -- returns Optional --> B[BackgroundTaskSqlRepository]
  B -- provides Optional --> C[Scheduled Services]
  C -- consumes Optional --> D[FetchAllLeetcodeQuestions]
  C -- consumes Optional --> E[AddUserMetricsService]
  F[BackgroundTaskRepositoryTest] -- validates Optional --> A
Loading

File Walkthrough

Relevant files
Enhancement
4 files
BackgroundTaskRepository.java
Update interface methods to return Optional for task retrieval
+3/-2     
BackgroundTaskSqlRepository.java
Implement Optional return types for BackgroundTask retrieval methods
+8/-6     
FetchAllLeetcodeQuestions.java
Update scheduled task to consume Optional from
BackgroundTaskRepository
+7/-4     
AddUserMetricsService.java
Adjust user metrics service to handle Optional BackgroundTask results
+5/-4     
Tests
3 files
BackgroundTaskRepositoryTest.java
Refactor unit tests to assert Optional presence and values
+26/-24 
FetchAllLeetcodeQuestionsTest.java
Update mock behavior to return Optional for background task
+2/-1     
AddUserMetricsServiceTest.java
Modify mock to return Optional for background task in tests
+2/-2     

@github-actions

Copy link
Copy Markdown
Contributor

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

**🎫 Ticket compliance analysis **

⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Redundant Assertion

In testCreateAnotherBackgroundTask, the assertion assertNotNull(found) on line 115 is redundant. Since found is an Optional object, it will never be null itself. The assertTrue(found.isPresent()) check is sufficient to verify that a value is present within the Optional.

assertNotNull(found);

@github-actions

Copy link
Copy Markdown
Contributor

Title

872: Migrate BackgroundTask to use Optional


PR Type

Enhancement


Description

  • Migrates BackgroundTaskRepository read methods to return Optional.

  • Updates BackgroundTaskSqlRepository to implement Optional returns.

  • Adapts scheduled tasks to handle Optional<BackgroundTask>.

  • Refactors unit tests to verify Optional behavior.


Diagram Walkthrough

flowchart LR
  A[BackgroundTaskRepository] --> B{Return Optional<BackgroundTask>};
  B --> C[BackgroundTaskSqlRepository];
  C -- Implements Optional returns --> D[Scheduled Tasks];
  D -- Adapts to Optional --> E[Unit Tests];
  E -- Verify Optional behavior --> A;
Loading

File Walkthrough

Relevant files
Enhancement
4 files
BackgroundTaskRepository.java
Updates `BackgroundTaskRepository` methods to return `Optional`.
+3/-2     
BackgroundTaskSqlRepository.java
Implements Optional return types for BackgroundTask read operations.
+8/-6     
FetchAllLeetcodeQuestions.java
Adapts `FetchAllLeetcodeQuestions` to handle `Optional` returns.
+7/-4     
AddUserMetricsService.java
Adapts `AddUserMetricsService` to handle `Optional` returns.
+5/-4     
Tests
3 files
BackgroundTaskRepositoryTest.java
Updates BackgroundTaskRepository tests to verify Optional behavior.
+27/-25 
FetchAllLeetcodeQuestionsTest.java
Updates mocks in FetchAllLeetcodeQuestionsTest to return Optional.
+2/-1     
AddUserMetricsServiceTest.java
Updates mocks in `AddUserMetricsServiceTest` to return `Optional`.
+2/-2     

@github-actions

Copy link
Copy Markdown
Contributor

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis ✅

872 - PR Code Verified

Compliant requirements:

  • Migrate BackgroundTaskRepository methods to return Optional<BackgroundTask>.
  • Update all call sites of BackgroundTaskRepository methods to handle Optional.
  • Update relevant tests to use Optional assertions.

Requires further human verification:

  • Verify that all tests have passed.
  • Verify successful deployment to staging.
  • Verify manual QA in dev and staging.
⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ No major issues detected

@github-actions

Copy link
Copy Markdown
Contributor

PR Code Suggestions ✨

No code suggestions found for the PR.

@luoh00

luoh00 commented Apr 17, 2026

Copy link
Copy Markdown
Contributor Author

/deploy

@github-actions

Copy link
Copy Markdown
Contributor

Title

872: Migrate BackgroundTask to use Optional


PR Type

Enhancement


Description

  • Migrate BackgroundTaskRepository methods to Optional.

  • Update BackgroundTaskSqlRepository to return Optional.of() or Optional.empty().

  • Adjust scheduled tasks to handle Optional return types.

  • Refactor tests to assert Optional.isPresent() and Optional.isEmpty().


Diagram Walkthrough

flowchart LR
  A["BackgroundTaskRepository (Interface)"] --> B["BackgroundTaskSqlRepository (Implementation)"]
  B --> C["FetchAllLeetcodeQuestions (Scheduled Task)"]
  B --> D["AddUserMetricsService (Scheduled Task)"]
  B --> E["BackgroundTaskRepositoryTest (Tests)"]
  C --> F["FetchAllLeetcodeQuestionsTest (Tests)"]
  D --> G["AddUserMetricsServiceTest (Tests)"]
  A -- "Return Optional<BackgroundTask>" --> B
  B -- "Implement Optional returns" --> C
  B -- "Implement Optional returns" --> D
  B -- "Implement Optional returns" --> E
  C -- "Consume Optional" --> F
  D -- "Consume Optional" --> G
Loading

File Walkthrough

Relevant files
Enhancement
4 files
BackgroundTaskRepository.java
Update `BackgroundTaskRepository` methods to return `Optional`
+3/-2     
BackgroundTaskSqlRepository.java
Implement Optional return types for BackgroundTaskSqlRepository
methods
+8/-6     
FetchAllLeetcodeQuestions.java
Adjust FetchAllLeetcodeQuestions to handle Optional from repository
+7/-4     
AddUserMetricsService.java
Update `AddUserMetricsService` to consume `Optional` from repository
+5/-4     
Tests
3 files
BackgroundTaskRepositoryTest.java
Refactor BackgroundTaskRepositoryTest assertions for Optional returns
+35/-25 
FetchAllLeetcodeQuestionsTest.java
Update `FetchAllLeetcodeQuestionsTest` mocks for `Optional` returns
+2/-1     
AddUserMetricsServiceTest.java
Adjust `AddUserMetricsServiceTest` mocks for `Optional` returns
+2/-2     

@github-actions

Copy link
Copy Markdown
Contributor

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis 🔶

Migrate-BackgroundTask-BackgroundTaskRepository-to-use-Optional-3267c85563aa80cd8c35fb2ff35130b5 - Partially compliant

Compliant requirements:

  • Migrate from using null to using Optional for BackgroundTask and related files.
  • I have done a thorough self-review of the PR.
  • If I have made database changes, I have made sure I followed all the db repo rules listed in the wiki.
  • All tests have passed.

Non-compliant requirements:

  • Copilot has reviewed my latest changes, and all comments have been fixed and/or closed.
  • I have successfully deployed this PR to staging.
  • I have done manual QA in both dev (and staging if possible) and attached screenshots below.

Requires further human verification:

  • Copilot has reviewed my latest changes, and all comments have been fixed and/or closed.
  • I have successfully deployed this PR to staging.
  • I have done manual QA in both dev (and staging if possible) and attached screenshots below.
⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Missing Javadoc

The newly introduced methods getBackgroundTaskById and getMostRecentlyCompletedBackgroundTaskByTaskEnum in the BackgroundTaskRepository interface are missing Javadoc comments. While the change to Optional is clear, adding Javadoc would align with existing documentation patterns and improve clarity for future maintainers, especially regarding the return behavior when no task is found.

Optional<BackgroundTask> getBackgroundTaskById(String id);

List<BackgroundTask> getBackgroundTasksByTaskEnum(BackgroundTaskEnum taskEnum);

Optional<BackgroundTask> getMostRecentlyCompletedBackgroundTaskByTaskEnum(BackgroundTaskEnum taskEnum);
Inconsistent Exception Handling

The getBackgroundTaskById and getMostRecentlyCompletedBackgroundTaskByTaskEnum methods catch Exception and rethrow a RuntimeException. While this is consistent with other methods in this class, it's generally better to catch more specific exceptions (e.g., SQLException) and wrap them in a custom data access exception or a more descriptive RuntimeException to provide clearer context about the failure.

} catch (Exception e) {
    throw new RuntimeException("Failed to get background task by ID", e);
}

@github-actions

Copy link
Copy Markdown
Contributor

PR Code Suggestions ✨

No code suggestions found for the PR.

@luoh00 luoh00 closed this Apr 19, 2026
@luoh00 luoh00 reopened this Apr 19, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Title

872: Migrate BackgroundTask to use Optional


PR Type

Enhancement, Bug fix, Tests


Description

  • Migrate BackgroundTaskRepository methods to return Optional.

  • Update SQL repository to return Optional.of() or Optional.empty().

  • Adapt scheduled services to handle Optional return types.

  • Refactor unit tests to assert Optional presence and value.


Diagram Walkthrough

flowchart LR
  A[BackgroundTaskRepository Interface] -- "Return Optional<BackgroundTask>" --> B[BackgroundTaskSqlRepository Implementation]
  B -- "Provides Optional<BackgroundTask>" --> C[FetchAllLeetcodeQuestions Service]
  B -- "Provides Optional<BackgroundTask>" --> D[AddUserMetricsService Service]
  E[BackgroundTaskRepositoryTest] -- "Tests Optional behavior" --> A
  E -- "Tests Optional behavior" --> B
Loading

File Walkthrough

Relevant files
Api change
1 files
BackgroundTaskRepository.java
Update BackgroundTaskRepository interface methods to return Optional.
+3/-2     
Enhancement
1 files
BackgroundTaskSqlRepository.java
Implement Optional return types for BackgroundTask database queries.
+8/-6     
Refactoring
2 files
FetchAllLeetcodeQuestions.java
Adapt FetchAllLeetcodeQuestions service to use Optional for background
tasks.
+7/-4     
AddUserMetricsService.java
Update AddUserMetricsService to handle Optional background task
results.
+5/-4     
Tests
3 files
BackgroundTaskRepositoryTest.java
Refactor BackgroundTaskRepository tests to validate Optional return
types.
+35/-25 
FetchAllLeetcodeQuestionsTest.java
Update FetchAllLeetcodeQuestions tests to mock Optional return values.
+2/-1     
AddUserMetricsServiceTest.java
Adjust AddUserMetricsService tests to mock Optional background task
results.
+2/-2     

@github-actions

Copy link
Copy Markdown
Contributor

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

**🎫 Ticket compliance analysis **

⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ No major issues detected

@github-actions

Copy link
Copy Markdown
Contributor

PR Code Suggestions ✨

No code suggestions found for the PR.

@github-actions

Copy link
Copy Markdown
Contributor

Title

872: Migrate BackgroundTask to use Optional


PR Type

Enhancement, Tests


Description

  • Migrates BackgroundTaskRepository read methods to return Optional.

  • Updates BackgroundTaskSqlRepository implementation to use Optional.

  • Refactors scheduled tasks to handle Optional for background tasks.

  • Enhances unit tests to validate Optional return types and behavior.


File Walkthrough

Relevant files
Enhancement
4 files
BackgroundTaskRepository.java
Update `BackgroundTaskRepository` interface to return `Optional`
+3/-2     
BackgroundTaskSqlRepository.java
Implement Optional returns for BackgroundTask SQL repository methods
+8/-6     
FetchAllLeetcodeQuestions.java
Adapt FetchAllLeetcodeQuestions to handle Optional background tasks
+7/-4     
AddUserMetricsService.java
Adjust `AddUserMetricsService` to process `Optional` background tasks
+5/-4     
Tests
4 files
BackgroundTaskRepositoryTest.java
Update `BackgroundTaskRepository` tests for `Optional` return types
+35/-25 
FetchAllLeetcodeQuestionsTest.java
Update `FetchAllLeetcodeQuestions` tests to mock `Optional` returns
+2/-1     
LeetcodeQuestionProcessServiceTest.java
Adjust `nextAttemptAt` in `LeetcodeQuestionProcessService` test job
+1/-1     
AddUserMetricsServiceTest.java
Update `AddUserMetricsService` tests to mock `Optional` returns
+2/-2     

@github-actions

Copy link
Copy Markdown
Contributor

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

**🎫 Ticket compliance analysis **

⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ No major issues detected

@github-actions

Copy link
Copy Markdown
Contributor

Title

872: Migrate BackgroundTask to use Optional


PR Type

Enhancement


Description

  • Migrate BackgroundTaskRepository read methods to Optional.

  • Update BackgroundTaskSqlRepository to return Optional.

  • Refactor scheduled tasks to consume Optional results.

  • Update unit and integration tests for Optional handling.


Diagram Walkthrough

flowchart LR
  RepoInterface["BackgroundTaskRepository Interface"] -- "Return Optional" --> RepoImpl["BackgroundTaskSqlRepository Implementation"]
  RepoImpl -- "Implement Optional" --> Consumers["Scheduled Task Services"]
  Consumers -- "Adapt to Optional" --> Tests["Unit/Integration Tests"]
  Tests -- "Validate Optional Usage" --> NullSafety["Improved Null Safety"]
Loading

File Walkthrough

Relevant files
Interface change
1 files
BackgroundTaskRepository.java
Update read methods to return Optional for null safety     
+3/-2     
Implementation change
1 files
BackgroundTaskSqlRepository.java
Implement Optional return types for background task queries
+8/-6     
Refactoring
2 files
FetchAllLeetcodeQuestions.java
Update scheduled task to consume Optional from repository
+7/-4     
AddUserMetricsService.java
Update user metrics service to consume Optional from repository
+5/-4     
Tests
3 files
BackgroundTaskRepositoryTest.java
Update repository tests to assert Optional presence and values
+27/-25 
FetchAllLeetcodeQuestionsTest.java
Update mock behavior to return Optional for background task
+2/-1     
AddUserMetricsServiceTest.java
Update mock behavior to return Optional for background task
+2/-2     

@github-actions

Copy link
Copy Markdown
Contributor

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

**🎫 Ticket compliance analysis **

⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ No major issues detected

@github-actions

Copy link
Copy Markdown
Contributor

PR Code Suggestions ✨

No code suggestions found for the PR.

@github-actions

Copy link
Copy Markdown
Contributor

Title

872: Migrate BackgroundTask to use Optional


PR Type

Enhancement


Description

  • Migrate BackgroundTaskRepository methods to Optional.

  • Update BackgroundTaskSqlRepository to return Optional.

  • Adapt scheduled tasks to handle Optional return types.

  • Enhance unit tests for Optional handling.


Diagram Walkthrough

flowchart LR
  A["BackgroundTaskRepository (Interface)"]
  B["BackgroundTaskSqlRepository (Implementation)"]
  C["Scheduled Services (Consumers)"]
  D["Unit Tests"]

  A -- "API Change" --> B
  B -- "Usage Update" --> C
  A -- "Test Adaptation" --> D
  C -- "Test Adaptation" --> D
Loading

File Walkthrough

Relevant files
Enhancement
4 files
BackgroundTaskRepository.java
Update BackgroundTaskRepository methods to return Optional
+3/-2     
BackgroundTaskSqlRepository.java
Implement Optional return types for BackgroundTaskSqlRepository
+8/-6     
FetchAllLeetcodeQuestions.java
Adapt FetchAllLeetcodeQuestions to use Optional for background tasks
+7/-4     
AddUserMetricsService.java
Update AddUserMetricsService to handle Optional background tasks
+5/-4     
Tests
3 files
BackgroundTaskRepositoryTest.java
Refactor BackgroundTaskRepository tests for Optional return types
+35/-25 
FetchAllLeetcodeQuestionsTest.java
Adjust FetchAllLeetcodeQuestionsTest mocks for Optional returns
+2/-1     
AddUserMetricsServiceTest.java
Update AddUserMetricsServiceTest mocks to return Optional
+2/-2     

@github-actions

Copy link
Copy Markdown
Contributor

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

**🎫 Ticket compliance analysis **

⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ No major issues detected

@github-actions

Copy link
Copy Markdown
Contributor

Title

872: Migrate BackgroundTask to use Optional


PR Type

Enhancement


Description

  • Migrate BackgroundTaskRepository methods to Optional.

  • Update BackgroundTaskSqlRepository to return Optional.

  • Adapt scheduled services to handle Optional BackgroundTask.

  • Refactor repository tests for Optional assertions.


Diagram Walkthrough

flowchart LR
  A["BackgroundTaskRepository (Interface)"] --> B["BackgroundTaskSqlRepository (Implementation)"]
  B -- "Returns Optional<BackgroundTask>" --> C["Scheduled Services (Consumers)"]
  A -- "Tested by" --> D["BackgroundTaskRepositoryTest"]
  C -- "Includes" --> E["FetchAllLeetcodeQuestions"]
  C -- "Includes" --> F["AddUserMetricsService"]
Loading

File Walkthrough

Relevant files
Interface change
1 files
BackgroundTaskRepository.java
Update `BackgroundTaskRepository` methods to return `Optional`.
+3/-2     
Implementation change
1 files
BackgroundTaskSqlRepository.java
Implement `Optional` returns for `BackgroundTask` queries.
+8/-6     
Refactoring
2 files
FetchAllLeetcodeQuestions.java
Adapt FetchAllLeetcodeQuestions to Optional BackgroundTask returns.
+7/-4     
AddUserMetricsService.java
Update `AddUserMetricsService` to handle `Optional` `BackgroundTask`.
+5/-4     
Tests
2 files
BackgroundTaskRepositoryTest.java
Update `BackgroundTaskRepository` tests for `Optional` returns.
+35/-25 
FetchAllLeetcodeQuestionsTest.java
Adjust `FetchAllLeetcodeQuestions` tests for `Optional` mocks.
+49/-5   
Additional files
1 files
AddUserMetricsServiceTest.java +2/-2     

@github-actions

Copy link
Copy Markdown
Contributor

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

**🎫 Ticket compliance analysis **

⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ No major issues detected

@github-actions

Copy link
Copy Markdown
Contributor

PR Code Suggestions ✨

No code suggestions found for the PR.

@github-actions

Copy link
Copy Markdown
Contributor

Title

872: Migrate BackgroundTask to use Optional


PR Type

Enhancement, Tests


Description

  • Migrate BackgroundTaskRepository methods to Optional.

  • Update BackgroundTaskSqlRepository for Optional returns.

  • Adapt scheduled tasks to handle Optional results.

  • Refactor repository tests for Optional assertions.


Diagram Walkthrough

flowchart LR
  A[BackgroundTaskRepository Interface] --> B{Update return types to Optional};
  B --> C[BackgroundTaskSqlRepository Implementation];
  C -- Implement Optional returns --> D[Scheduled Tasks (FetchAllLeetcodeQuestions, AddUserMetricsService)];
  D -- Adapt to Optional --> E[BackgroundTaskRepositoryTest];
  E -- Update assertions --> F[FetchAllLeetcodeQuestionsTest, AddUserMetricsServiceTest];
  F -- Update mocks --> G[Completed Migration];
Loading

File Walkthrough

Relevant files
Enhancement
2 files
BackgroundTaskRepository.java
Update `BackgroundTaskRepository` methods to return `Optional`
+3/-2     
BackgroundTaskSqlRepository.java
Implement `Optional` return types for `BackgroundTask` queries
+8/-6     
Refactoring
2 files
FetchAllLeetcodeQuestions.java
Adjust `updateQuestionBank` to handle `Optional`
+7/-4     
AddUserMetricsService.java
Update `congregateUserMetrics` to process `Optional`
+5/-4     
Tests
3 files
BackgroundTaskRepositoryTest.java
Refactor tests to assert `Optional` presence and values   
+27/-25 
FetchAllLeetcodeQuestionsTest.java
Update mocks for `Optional` and add invalid difficulty test
+49/-5   
AddUserMetricsServiceTest.java
Adjust mocks to return `Optional`               
+2/-2     

@github-actions

Copy link
Copy Markdown
Contributor

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

**🎫 Ticket compliance analysis **

⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ No major issues detected

@luoh00 luoh00 closed this Apr 21, 2026
@luoh00 luoh00 reopened this Apr 21, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Title

872: Migrate BackgroundTask to use Optional


PR Type

Enhancement, Tests


Description

  • Migrated BackgroundTaskRepository methods to return Optional.

  • Updated BackgroundTaskSqlRepository to implement Optional returns.

  • Refactored scheduled tasks to correctly handle Optional results.

  • Enhanced unit tests to validate Optional behavior and added a new test.


Diagram Walkthrough

flowchart LR
  A[BackgroundTaskRepository] -- "Returns Optional<BackgroundTask>" --> B[BackgroundTaskSqlRepository]
  B -- "Provides Optional<BackgroundTask>" --> C[FetchAllLeetcodeQuestions]
  B -- "Provides Optional<BackgroundTask>" --> D[AddUserMetricsService]
  B -- "Provides Optional<BackgroundTask>" --> E[BackgroundTaskRepositoryTest]
  C -- "Consumes Optional" --> F[FetchAllLeetcodeQuestionsTest]
  D -- "Consumes Optional" --> G[AddUserMetricsServiceTest]
Loading

File Walkthrough

Relevant files
Enhancement
4 files
BackgroundTaskRepository.java
Updated `BackgroundTaskRepository` methods to return `Optional`.
+3/-2     
BackgroundTaskSqlRepository.java
Implemented `Optional` return types for `BackgroundTask` queries.
+8/-6     
FetchAllLeetcodeQuestions.java
Adapted scheduled task to handle `Optional` `BackgroundTask` results.
+7/-4     
AddUserMetricsService.java
Updated user metrics service to process `Optional` `BackgroundTask`.
+5/-4     
Tests
3 files
BackgroundTaskRepositoryTest.java
Modified tests to assert Optional presence and absence for
BackgroundTask.
+27/-25 
FetchAllLeetcodeQuestionsTest.java
Updated mocks for Optional returns and added invalid difficulty test.
+49/-5   
AddUserMetricsServiceTest.java
Adjusted mocks to return `Optional` `BackgroundTask` objects.
+2/-2     

@github-actions

Copy link
Copy Markdown
Contributor

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis 🔶

872 - Partially compliant

Compliant requirements:

  • getBackgroundTaskById(String id) and getMostRecentlyCompletedBackgroundTaskByTaskEnum(BackgroundTaskEnum taskEnum) in BackgroundTaskRepository now return Optional<BackgroundTask>.
  • The implementations in BackgroundTaskSqlRepository correctly return Optional.of() or Optional.empty().
  • Call sites in FetchAllLeetcodeQuestions.java and AddUserMetricsService.java are updated to use Optional.isPresent() and Optional.get().
  • All relevant tests in BackgroundTaskRepositoryTest.java, FetchAllLeetcodeQuestionsTest.java, and AddUserMetricsServiceTest.java have been updated to assert on Optional values.

Non-compliant requirements:

  • None

Requires further human verification:

  • The Notion ticket title (873) refers to SessionRepository, while the PR title (872) and implementation are for BackgroundTaskRepository. This is a discrepancy in ticket/PR alignment that should be verified by a human.
⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ No major issues detected

@github-actions

Copy link
Copy Markdown
Contributor

PR Code Suggestions ✨

No code suggestions found for the PR.

@github-actions

Copy link
Copy Markdown
Contributor

Title

872: Migrate BackgroundTask to use Optional


PR Type

Enhancement


Description

  • Migrate BackgroundTaskRepository methods to return Optional.

  • Update BackgroundTaskSqlRepository to implement Optional returns.

  • Adjust scheduled tasks to handle Optional for background tasks.

  • Refactor unit tests to assert Optional presence and values.


Diagram Walkthrough

flowchart LR
  BackgroundTaskRepository["BackgroundTaskRepository (Interface)"]
  BackgroundTaskSqlRepository["BackgroundTaskSqlRepository (Implementation)"]
  FetchAllLeetcodeQuestions["FetchAllLeetcodeQuestions (Scheduled Task)"]
  AddUserMetricsService["AddUserMetricsService (Scheduled Task)"]
  BackgroundTaskRepositoryTest["BackgroundTaskRepositoryTest (Unit Test)"]

  BackgroundTaskRepository -- "Defines methods returning Optional" --> BackgroundTaskSqlRepository
  BackgroundTaskSqlRepository -- "Implements Optional returns" --> BackgroundTaskRepository
  FetchAllLeetcodeQuestions -- "Consumes Optional from Repository" --> BackgroundTaskRepository
  AddUserMetricsService -- "Consumes Optional from Repository" --> BackgroundTaskRepository
  BackgroundTaskRepositoryTest -- "Tests Optional handling" --> BackgroundTaskRepository
Loading

File Walkthrough

Relevant files
Enhancement
4 files
BackgroundTaskRepository.java
Update repository interface methods to return Optional     
+3/-2     
BackgroundTaskSqlRepository.java
Implement Optional returns for background task queries     
+8/-6     
FetchAllLeetcodeQuestions.java
Adjust Leetcode question sync to handle Optional background tasks
+7/-4     
AddUserMetricsService.java
Update user metrics service to handle Optional background tasks
+5/-4     
Tests
3 files
BackgroundTaskRepositoryTest.java
Refactor background task repository tests for Optional assertions
+31/-25 
FetchAllLeetcodeQuestionsTest.java
Update Leetcode question sync tests for Optional and add invalid
difficulty test
+49/-5   
AddUserMetricsServiceTest.java
Update user metrics service tests to handle Optional background tasks
+2/-2     

@github-actions

Copy link
Copy Markdown
Contributor

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

**🎫 Ticket compliance analysis **

⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ No major issues detected

@luoh00

luoh00 commented Apr 22, 2026

Copy link
Copy Markdown
Contributor Author

/deploy

@github-actions

Copy link
Copy Markdown
Contributor

Title

872: Migrate BackgroundTask to use Optional


PR Type

Enhancement


Description

  • Migrate BackgroundTaskRepository methods to return Optional.

  • Update BackgroundTaskSqlRepository to implement Optional returns.

  • Refactor scheduled tasks to handle Optional results.

  • Adjust unit tests to assert Optional presence and emptiness.


Diagram Walkthrough

flowchart LR
  A[BackgroundTaskRepository Interface] --> B{getBackgroundTaskById, getMostRecentlyCompletedBackgroundTaskByTaskEnum};
  B --> C[BackgroundTaskSqlRepository Implementation];
  C -- returns Optional --> D[FetchAllLeetcodeQuestions];
  C -- returns Optional --> E[AddUserMetricsService];
  C -- returns Optional --> F[BackgroundTaskRepositoryTest];
  D -- consumes Optional --> G[Scheduled Task Logic];
  E -- consumes Optional --> H[Scheduled Task Logic];
  F -- asserts Optional --> I[Test Assertions];
Loading

File Walkthrough

Relevant files
Enhancement
2 files
BackgroundTaskRepository.java
Update `BackgroundTaskRepository` methods to return `Optional`.
+3/-2     
BackgroundTaskSqlRepository.java
Implement `Optional` returns for `BackgroundTask` SQL queries.
+8/-6     
Refactoring
2 files
FetchAllLeetcodeQuestions.java
Adapt `FetchAllLeetcodeQuestions` to handle `Optional` task.
+7/-4     
AddUserMetricsService.java
Update `AddUserMetricsService` to process `Optional` task.
+5/-4     
Tests
3 files
BackgroundTaskRepositoryTest.java
Update `BackgroundTaskRepositoryTest` for `Optional` assertions.
+31/-25 
FetchAllLeetcodeQuestionsTest.java
Adjust `FetchAllLeetcodeQuestionsTest` mocks and add new test.
+49/-5   
AddUserMetricsServiceTest.java
Update `AddUserMetricsServiceTest` mocks for `Optional`. 
+2/-2     

@github-actions

Copy link
Copy Markdown
Contributor

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis 🔶

872 - Partially compliant

Compliant requirements:

  • getBackgroundTaskById in BackgroundTaskRepository now returns Optional<BackgroundTask>.
  • getMostRecentlyCompletedBackgroundTaskByTaskEnum in BackgroundTaskRepository now returns Optional<BackgroundTask>.
  • BackgroundTaskSqlRepository implementation correctly returns Optional.of() or Optional.empty().
  • FetchAllLeetcodeQuestions updated to handle Optional<BackgroundTask>.
  • AddUserMetricsService updated to handle Optional<BackgroundTask>.
  • BackgroundTaskRepositoryTest updated to use Optional assertions.
  • FetchAllLeetcodeQuestionsTest updated to use Optional mocks.
  • AddUserMetricsServiceTest updated to use Optional mocks.

Non-compliant requirements:

  • The PR is linked to a Notion ticket titled '873: Migrate session to use optional', but the PR itself implements the migration for BackgroundTask (ID 872). This is a mismatch between the PR's content and its linked ticket.

Requires further human verification:

  • Verify that the correct Notion ticket (for BackgroundTask) exists and should be linked instead.
  • Manual QA for the scheduled tasks (FetchAllLeetcodeQuestions, AddUserMetricsService) to ensure they run correctly with the Optional changes.
⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ No major issues detected

@github-actions

Copy link
Copy Markdown
Contributor

PR Code Suggestions ✨

No code suggestions found for the PR.

luoh00 added 2 commits April 23, 2026 17:59
Modified two methods inside BackgroundTaskRepository.java to use
Java Optional, returning Optional.of() if non-null and replacing
null returns with Optional.empty(), and updated call sites in other
classes and test files, to avoid possibility of null pointer exceptions
and null checks.
Modified tests to reach sonarqube code coverage
@github-actions

Copy link
Copy Markdown
Contributor

Title

872: Migrate BackgroundTask to use Optional


PR Type

Enhancement, Bug fix


Description

  • Migrated BackgroundTaskRepository read methods to return Optional.

  • Updated BackgroundTaskSqlRepository to implement Optional returns.

  • Refactored scheduled tasks to handle Optional<BackgroundTask>.

  • Enhanced BackgroundTaskRepositoryTest for Optional assertions.


Diagram Walkthrough

flowchart LR
  A[BackgroundTaskRepository Interface] -- "Return Optional<BackgroundTask>" --> B[BackgroundTaskSqlRepository Implementation]
  B -- "Provides Optional<BackgroundTask>" --> C[FetchAllLeetcodeQuestions Scheduled Task]
  B -- "Provides Optional<BackgroundTask>" --> D[AddUserMetricsService Scheduled Task]
  A -- "Tested by" --> E[BackgroundTaskRepositoryTest]
  C -- "Tested by" --> F[FetchAllLeetcodeQuestionsTest]
Loading

File Walkthrough

Relevant files
Api change
1 files
BackgroundTaskRepository.java
Update read methods to return Optional     
+3/-2     
Implementation
1 files
BackgroundTaskSqlRepository.java
Implement Optional returns for read methods
+8/-6     
Refactoring
2 files
FetchAllLeetcodeQuestions.java
Update scheduled task to handle Optional 
+7/-4     
AddUserMetricsService.java
Update scheduled service to handle Optional
+5/-4     
Tests
3 files
BackgroundTaskRepositoryTest.java
Refactor tests to assert Optional presence and value
+31/-25 
FetchAllLeetcodeQuestionsTest.java
Update mock behavior for Optional and add invalid difficulty test
+49/-5   
AddUserMetricsServiceTest.java
Update mock behavior for Optional               
+2/-2     

@github-actions

Copy link
Copy Markdown
Contributor

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis 🔶

872 - Partially compliant

Compliant requirements:

  • Migrate BackgroundTaskRepository to use Optional for methods that might return null.
  • Update all call sites of BackgroundTaskRepository methods to handle Optional.
  • Ensure proper error handling and edge cases are covered.
  • Update relevant tests.

Non-compliant requirements:

  • The ticket title and description refer to SessionRepository, but the PR implements changes for BackgroundTaskRepository. This is a mismatch between the ticket and the PR's scope.

Requires further human verification:

  • Manual QA in dev/staging (screenshots are marked n/a in PR description)
⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ No major issues detected

@luoh00

luoh00 commented Apr 23, 2026

Copy link
Copy Markdown
Contributor Author

/deploy

@luoh00 luoh00 merged commit 69c593c into main Apr 23, 2026
41 of 42 checks passed
@luoh00 luoh00 deleted the 872 branch April 23, 2026 23:01
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