fix(api): ignore unused tasks to stop warnings (#2213)
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package org.booklore.repository;
|
||||
|
||||
import org.booklore.model.entity.TaskHistoryEntity;
|
||||
import org.booklore.model.enums.TaskType;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.stereotype.Repository;
|
||||
@@ -10,8 +11,13 @@ import java.util.List;
|
||||
@Repository
|
||||
public interface TaskHistoryRepository extends JpaRepository<TaskHistoryEntity, String> {
|
||||
|
||||
@Query("SELECT t FROM TaskHistoryEntity t WHERE t.createdAt = " +
|
||||
"(SELECT MAX(t2.createdAt) FROM TaskHistoryEntity t2 WHERE t2.type = t.type) " +
|
||||
"ORDER BY t.createdAt DESC")
|
||||
List<TaskHistoryEntity> findLatestTaskForEachType();
|
||||
@Query("""
|
||||
SELECT t FROM TaskHistoryEntity t
|
||||
WHERE
|
||||
t.createdAt = (SELECT MAX(t2.createdAt) FROM TaskHistoryEntity t2 WHERE t2.type = t.type)
|
||||
AND
|
||||
t.type IN (:taskTypes)
|
||||
ORDER BY t.createdAt DESC
|
||||
""")
|
||||
List<TaskHistoryEntity> findLatestTaskForEachType(List<TaskType> taskTypes);
|
||||
}
|
||||
|
||||
@@ -110,7 +110,8 @@ public class TaskHistoryService {
|
||||
public TasksHistoryResponse getLatestTasksForEachType() {
|
||||
List<TaskHistoryEntity> latestTasks;
|
||||
try {
|
||||
latestTasks = taskHistoryRepository.findLatestTaskForEachType();
|
||||
// Limits to all task types so we ignore older deprecated task types that are no longer in the enum
|
||||
latestTasks = taskHistoryRepository.findLatestTaskForEachType(Arrays.asList(TaskType.values()));
|
||||
} catch (Exception e) {
|
||||
log.warn("Error fetching latest tasks, possibly due to removed enum values: {}", e.getMessage());
|
||||
latestTasks = Collections.emptyList();
|
||||
|
||||
Reference in New Issue
Block a user