perf: 일정 페이지 월별 데이터 로딩으로 변경

- 프론트엔드: currentDate 변경 시 해당 월 일정만 로드
- 백엔드: /api/schedules에 year/month 파라미터 지원 추가
- 초기 로딩 속도 개선 (전체 로드 → 월별 로드)
This commit is contained in:
caadiq 2026-01-09 21:38:29 +09:00
parent 2b6fa74eb8
commit 80fad4d055
2 changed files with 21 additions and 4 deletions

View file

@ -7,7 +7,7 @@ const router = express.Router();
// 공개 일정 목록 조회 (검색 포함)
router.get("/", async (req, res) => {
try {
const { search, startDate, endDate, limit } = req.query;
const { search, startDate, endDate, limit, year, month } = req.query;
// 검색어가 있으면 Meilisearch 사용
if (search && search.trim()) {
@ -30,6 +30,15 @@ router.get("/", async (req, res) => {
let whereClause = "WHERE 1=1";
const params = [];
// 년/월 필터링 (월별 데이터 로딩용)
if (year && month) {
whereClause += " AND YEAR(s.date) = ? AND MONTH(s.date) = ?";
params.push(parseInt(year), parseInt(month));
} else if (year) {
whereClause += " AND YEAR(s.date) = ?";
params.push(parseInt(year));
}
if (startDate) {
whereClause += " AND s.date >= ?";
params.push(startDate);

View file

@ -82,14 +82,22 @@ function Schedule() {
}, [inView, hasNextPage, isFetchingNextPage, fetchNextPage, isSearchMode, searchTerm]);
//
// ()
useEffect(() => {
fetchSchedules();
fetchCategories();
}, []);
//
useEffect(() => {
const year = currentDate.getFullYear();
const month = currentDate.getMonth();
fetchSchedules(year, month + 1);
}, [currentDate]);
const fetchSchedules = async () => {
const fetchSchedules = async (year, month) => {
setLoading(true);
try {
const response = await fetch('/api/schedules');
const response = await fetch(`/api/schedules?year=${year}&month=${month}`);
if (response.ok) {
const data = await response.json();
setSchedules(data);