I have a question about data performance
time value is stored as long in my spring boot application.
When I retrieve multiple data, I convert the time using Date_Format FROM_UNIXTIME like below
@Query("SELECT new today.feeling.dto.response.emotion.EmotionMonthlyReportQuery(" +
"s.id, " +
"s.studentId, " +
"s.name, " +
"CAST(DATE_FORMAT(FROM_UNIXTIME(e.emotionTime / 1000, '%Y-%m-%d %H:%i:%s'), '%Y-%m-%d') AS string) AS emotion_date, " +
"CAST(SUM(CASE WHEN e.emotionType = 1 THEN e.emotionLevel ELSE 0 END) / COUNT(CASE WHEN e.emotionType = 1 THEN 1 END) AS FLOAT), " +
"CAST(SUM(CASE WHEN e.emotionType = 2 THEN e.emotionLevel ELSE 0 END) / COUNT(CASE WHEN e.emotionType = 2 THEN 1 END) AS FLOAT), " +
"CAST(SUM(CASE WHEN e.emotionType = 3 THEN e.emotionLevel ELSE 0 END) / COUNT(CASE WHEN e.emotionType = 3 THEN 1 END) AS FLOAT), " +
"CAST(SUM(CASE WHEN e.emotionType = 4 THEN e.emotionLevel ELSE 0 END) / COUNT(CASE WHEN e.emotionType = 4 THEN 1 END) AS FLOAT)) " +
"FROM Emotion e " +
"JOIN Student s ON s.id = e.student.id " +
"WHERE s.isRemoved = FALSE AND s.classroom.id = :classroomId AND s.year = :year AND e.emotionTime BETWEEN :startDate AND :endDate " +
"GROUP BY s.id, emotion_date " +
"ORDER BY s.studentId, emotion_date")
List<EmotionMonthlyReportQuery> getEmotionMonthlyReportList(@Param("classroomId") Long classroomId,
@Param("year") Integer year,
@Param("startDate") long startDate,
@Param("endDate") long endDate);
Is it better to convert time in DB directly or in service layer?
I would like to know which approach is better in terms of performance or code separation