Skip to content

Commit 2e27b1d

Browse files
committed
feat: 지도 핀 bounds 조회 쿼리 보강
1 parent 8929503 commit 2e27b1d

4 files changed

Lines changed: 15 additions & 11 deletions

File tree

docker/postgres/init/01-postgis-init.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ BEGIN
6969
CREATE INDEX IF NOT EXISTS idx_lockers_location_geog
7070
ON public.lockers
7171
USING GIST (location);
72+
73+
CREATE INDEX IF NOT EXISTS idx_lockers_latitude_longitude
74+
ON public.lockers (latitude, longitude);
7275
END;
7376
$$;
7477

scripts/db/01-postgis.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ BEGIN
6666
CREATE INDEX IF NOT EXISTS idx_lockers_location_geog
6767
ON public.lockers
6868
USING GIST (location);
69+
70+
CREATE INDEX IF NOT EXISTS idx_lockers_latitude_longitude
71+
ON public.lockers (latitude, longitude);
6972
END;
7073
$$;;
7174

src/main/java/com/zimdugo/locker/infrastructure/persistence/LockerRepository.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -327,27 +327,25 @@ Optional<LockerDetailQueryProjection> findDetailById(
327327
);
328328

329329
@Query(value = """
330-
WITH target AS (
331-
SELECT ST_SetSRID(ST_MakePoint(:longitude, :latitude), 4326)::geography AS point
332-
)
333330
SELECT
334331
l.id AS lockerId,
335332
ST_Y(l.location::geometry) AS lockerLatitude,
336333
ST_X(l.location::geometry) AS lockerLongitude,
337334
l.place_id AS placeId
338335
FROM lockers l
339336
JOIN places p ON p.id = l.place_id
340-
CROSS JOIN target
341-
WHERE ST_DWithin(l.location, target.point, :radiusMeters)
337+
WHERE l.latitude BETWEEN :swLat AND :neLat
338+
AND l.longitude BETWEEN :swLng AND :neLng
342339
AND l.place_id IS NOT NULL
343340
AND l.publication_status = 'ACTIVE'
344341
AND p.publication_status = 'ACTIVE'
345-
ORDER BY ST_Distance(l.location, target.point) ASC
342+
ORDER BY l.id ASC
346343
""", nativeQuery = true)
347-
List<NearbyLockerPlaceQueryProjection> findNearbyLockers(
348-
@Param("latitude") double latitude,
349-
@Param("longitude") double longitude,
350-
@Param("radiusMeters") int radiusMeters
344+
List<NearbyLockerPlaceQueryProjection> findLockersWithinBounds(
345+
@Param("swLat") double swLat,
346+
@Param("swLng") double swLng,
347+
@Param("neLat") double neLat,
348+
@Param("neLng") double neLng
351349
);
352350

353351
@Query(value = """

src/test/java/com/zimdugo/locker/infrastructure/persistence/PublicationStatusRepositoryQueryTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class PublicationStatusRepositoryQueryTest {
1717
@DisplayName("모든 공개 보관함 조회는 활성 보관함만 반환한다")
1818
void lockerQueriesRequireActivePublicationStatus() {
1919
assertQueryContains(LockerRepository.class, "findDetailById", ACTIVE_LOCKER, ACTIVE_PLACE);
20-
assertQueryContains(LockerRepository.class, "findNearbyLockers", ACTIVE_LOCKER, ACTIVE_PLACE);
20+
assertQueryContains(LockerRepository.class, "findLockersWithinBounds", ACTIVE_LOCKER, ACTIVE_PLACE);
2121
assertQueryContains(LockerRepository.class, "findAllForSuggestIndex", ACTIVE_LOCKER, ACTIVE_PLACE);
2222
assertQueryContains(
2323
LockerRepository.class,

0 commit comments

Comments
 (0)