/cart/item
API 요청 시, cart_items
와 products
, inventory
간의 중첩 조인(select with nested) 을 통해 데이터를 불러왔습니다.
하지만 이 방식은 Supabase에서 조인 쿼리를 실행할 때 네트워크 응답 지연이 발생하고, 정확하지 않은 타입 추론을 반환하는 문제점이 있었습니다.
const { data, error } = await supabase
.from('cart_items')
.select(`
cart_item_id,
quantity,
inventory (
inventory_id,
size,
stock,
product (
product_id,
title,
price,
image
)
)
`)
.eq('user_id', userId);
복잡한 조인을 클라이언트에서 직접 수행하는 대신, Supabase View 테이블을 생성하여 서버에서 미리 가공된 형태로 응답 받을 수 있도록 구조를 단순화했습니다.
// 뷰에서 가공된 응답을 간단하게 조회
const { data, error } = await supabase
.from('cart_items_with_details')
.select('*')
.eq('user_id', userId);
POST /cart/item
TTFB(Time to First Byte) 기준 조회 응답 속도 약 83% 개선 할 수 있었습니다.