Skip to content
This repository has been archived by the owner on Aug 13, 2022. It is now read-only.

[#62] 현재 위치 주변의 매장을 검색하는 기능 구현 #64

Merged
merged 10 commits into from
Apr 23, 2021

Conversation

zeroooooowest
Copy link
Collaborator

@zeroooooowest zeroooooowest commented Apr 20, 2021

우선은 DB 스키마를 변경하였습니다.
기존의 위도 경도 각각 따로 저장하던 방식에서 MySQL의 Point 타입을 활용하였고 Spatial 인덱스를 걸어줬습니다. R-Tree 인덱스인 Spatial 인덱스를 활용하여 위치 기반 검색시 풀스캔을 하지 않고 빠르게 검색하기 위함입니다.
변경된 필드는 Location 이라는 클래스를 만들어서 Mybatis TypeHandler를 추가하여 처리하였습니다.

풀스캔하지 않는 쿼리 작성
쿼리의 WHERE절에서 ST_LINESTRING의 ST_ENVELOPE 를 활용하여 풀스캔하지 않도록 하였습니다.
현재 위치의 동서남북 지점을 구하기 위해 java geo library 등으로 검색해보고 이클립스 프로젝트인 Spatial4J 라는 라이브러리를 활용하였습니다.
로컬에서 데이터를 2만개 넣어보고 EXPLAIN을 통해 테스트해본결과 일부만 스캔하는 것을 확인하였습니다.

MySQL Console에서 한글 깨지던 현상 수정,
유니크 인덱스에서 중복이 아닌데도 중복 오류 나던 현상 해결
Office 테이블의 위치 정보에서
기존의 경도 위도 따로 저장하던 방식에서
POINT 타입 사용하도록 변경
@zeroooooowest zeroooooowest self-assigned this Apr 20, 2021
@zeroooooowest zeroooooowest linked an issue Apr 20, 2021 that may be closed by this pull request
private String address;

private String distance;

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

매장의 id는 필요하지 않을까요?
일반적으로 자원의 고유값을 통해서 클라이언트 측에서 요청이 들어옵니다. 매장의 이름이 유니크하긴 하나 다른 자원들과 같이 pk인 id를 제공해주고 요청도 id 받는 것으로 통일 시켜주는 편이 좋을 것 같다는 생각입니다.
또한 서버에서 주문을 처리할 떄 매장에 대한 유효성을 검증한다고 봐도 인덱스가 걸려있는 id로 조회하는 것이 효율적이라고 생각합니다.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

매장 조회하고 주문까지 생각을 못했네요 :(

@zeroooooowest zeroooooowest merged commit b956d4f into feature/61 Apr 23, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

사용자 인근 매장 조회 기능 추가
3 participants