refactor(backend): 순차 쿼리 → 병렬 처리
- getAlbumDetails: tracks/teasers/photos 쿼리 Promise.all로 병렬 실행 - photos.js: 멤버 INSERT for loop → VALUES 배치 처리 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
c3e504d1e3
commit
0a91d04992
3 changed files with 39 additions and 34 deletions
|
|
@ -166,14 +166,13 @@ export default async function photosRoutes(fastify) {
|
||||||
photoId = result.insertId;
|
photoId = result.insertId;
|
||||||
|
|
||||||
if (meta.members && meta.members.length > 0) {
|
if (meta.members && meta.members.length > 0) {
|
||||||
for (const memberId of meta.members) {
|
const values = meta.members.map(memberId => [photoId, memberId]);
|
||||||
await connection.query(
|
await connection.query(
|
||||||
'INSERT INTO album_photo_members (photo_id, member_id) VALUES (?, ?)',
|
'INSERT INTO album_photo_members (photo_id, member_id) VALUES ?',
|
||||||
[photoId, memberId]
|
[values]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
uploadedPhotos.push({
|
uploadedPhotos.push({
|
||||||
id: photoId,
|
id: photoId,
|
||||||
|
|
|
||||||
|
|
@ -10,20 +10,18 @@
|
||||||
* @returns {object} 상세 정보가 포함된 앨범
|
* @returns {object} 상세 정보가 포함된 앨범
|
||||||
*/
|
*/
|
||||||
export async function getAlbumDetails(db, album) {
|
export async function getAlbumDetails(db, album) {
|
||||||
const [tracks] = await db.query(
|
// 트랙, 티저, 포토 병렬 조회
|
||||||
|
const [[tracks], [teasers], [photos]] = await Promise.all([
|
||||||
|
db.query(
|
||||||
'SELECT * FROM album_tracks WHERE album_id = ? ORDER BY track_number',
|
'SELECT * FROM album_tracks WHERE album_id = ? ORDER BY track_number',
|
||||||
[album.id]
|
[album.id]
|
||||||
);
|
),
|
||||||
album.tracks = tracks;
|
db.query(
|
||||||
|
|
||||||
const [teasers] = await db.query(
|
|
||||||
`SELECT original_url, medium_url, thumb_url, video_url, media_type
|
`SELECT original_url, medium_url, thumb_url, video_url, media_type
|
||||||
FROM album_teasers WHERE album_id = ? ORDER BY sort_order`,
|
FROM album_teasers WHERE album_id = ? ORDER BY sort_order`,
|
||||||
[album.id]
|
[album.id]
|
||||||
);
|
),
|
||||||
album.teasers = teasers;
|
db.query(
|
||||||
|
|
||||||
const [photos] = await db.query(
|
|
||||||
`SELECT
|
`SELECT
|
||||||
p.id, p.original_url, p.medium_url, p.thumb_url, p.photo_type, p.concept_name, p.sort_order,
|
p.id, p.original_url, p.medium_url, p.thumb_url, p.photo_type, p.concept_name, p.sort_order,
|
||||||
p.width, p.height,
|
p.width, p.height,
|
||||||
|
|
@ -35,7 +33,11 @@ export async function getAlbumDetails(db, album) {
|
||||||
GROUP BY p.id
|
GROUP BY p.id
|
||||||
ORDER BY p.sort_order`,
|
ORDER BY p.sort_order`,
|
||||||
[album.id]
|
[album.id]
|
||||||
);
|
),
|
||||||
|
]);
|
||||||
|
|
||||||
|
album.tracks = tracks;
|
||||||
|
album.teasers = teasers;
|
||||||
|
|
||||||
const conceptPhotos = {};
|
const conceptPhotos = {};
|
||||||
for (const photo of photos) {
|
for (const photo of photos) {
|
||||||
|
|
|
||||||
|
|
@ -60,9 +60,13 @@
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
### 7단계: 순차 쿼리 → 병렬 처리
|
### 7단계: 순차 쿼리 → 병렬 처리 ✅ 완료
|
||||||
- [ ] `services/album.js` getAlbumDetails - tracks, teasers, photos 병렬 조회
|
- [x] `services/album.js` getAlbumDetails - tracks, teasers, photos 병렬 조회
|
||||||
- [ ] `routes/albums/photos.js` - 멤버 INSERT 배치 처리
|
- [x] `routes/albums/photos.js` - 멤버 INSERT 배치 처리
|
||||||
|
|
||||||
|
**수정된 파일:**
|
||||||
|
- `src/services/album.js` - Promise.all로 3개 쿼리 병렬 실행
|
||||||
|
- `src/routes/albums/photos.js` - for loop → VALUES ? 배치 INSERT
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|
@ -107,7 +111,7 @@
|
||||||
| 4단계 | 에러 처리 통일 | ✅ 완료 |
|
| 4단계 | 에러 처리 통일 | ✅ 완료 |
|
||||||
| 5단계 | 중복 코드 제거 | ✅ 완료 |
|
| 5단계 | 중복 코드 제거 | ✅ 완료 |
|
||||||
| 6단계 | 매직 넘버 config 이동 | ✅ 완료 |
|
| 6단계 | 매직 넘버 config 이동 | ✅ 완료 |
|
||||||
| 7단계 | 순차→병렬 쿼리 | 대기 |
|
| 7단계 | 순차→병렬 쿼리 | ✅ 완료 |
|
||||||
| 8단계 | meilisearch 카테고리 ID | 대기 |
|
| 8단계 | meilisearch 카테고리 ID | 대기 |
|
||||||
| 9단계 | 응답 형식 통일 | 대기 |
|
| 9단계 | 응답 형식 통일 | 대기 |
|
||||||
| 10단계 | 로거 통일 | 대기 |
|
| 10단계 | 로거 통일 | 대기 |
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue