-
Notifications
You must be signed in to change notification settings - Fork 0
Develop #117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Develop #117
Changes from all commits
2b56748
80f53ca
07de346
8abbe95
e2eaebc
341f589
d9bca99
26100ce
99bd377
1fb83f1
3c83d32
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| -- PostGIS geography ์ปฌ๋ผ ์ถ๊ฐ + GIST ์ธ๋ฑ์ค ๋ง์ด๊ทธ๋ ์ด์ | ||
| -- ์คํ: docker exec -i catchtable-db psql -U $DB_USER -d $DB_NAME < data/migration_v2_postgis_geography.sql | ||
| -- ๋ก์ปฌ์์ ์ด๋ฏธ ์คํํ๋ค๋ฉด ์ด์ ์๋ฒ์์๋ง ์คํํ ๊ฒ | ||
|
|
||
| -- 1. PostGIS ํ์ฅ ํ์ฑํ | ||
| CREATE EXTENSION IF NOT EXISTS postgis; | ||
|
|
||
| -- 2. stores ํ ์ด๋ธ์ geography ์ปฌ๋ผ ์ถ๊ฐ | ||
| -- geometry ๋์ geography ์ฌ์ฉ: ::geography ์บ์คํ ์์ด GIST ์ธ๋ฑ์ค ์ง์ ํ์ฉ ๊ฐ๋ฅ | ||
| ALTER TABLE stores | ||
| ADD COLUMN IF NOT EXISTS location geography(Point, 4326); | ||
|
|
||
| -- 3. ๊ธฐ์กด latitude/longitude ๋ฐ์ดํฐ๋ฅผ geography ์ปฌ๋ผ์ผ๋ก ๋ณต์ฌ | ||
| UPDATE stores | ||
| SET location = ST_SetSRID(ST_MakePoint(longitude, latitude), 4326)::geography | ||
| WHERE location IS NULL | ||
| AND latitude IS NOT NULL | ||
| AND longitude IS NOT NULL; | ||
|
|
||
| -- 4. GIST ๊ณต๊ฐ ์ธ๋ฑ์ค ์์ฑ | ||
| CREATE INDEX IF NOT EXISTS idx_stores_location_gist | ||
| ON stores USING GIST (location); | ||
|
|
||
| -- 5. nearby ๋ฐ์ด๋ฉ๋ฐ์ค ์ ํํฐ์ฉ ๋ณตํฉ B-tree ์ธ๋ฑ์ค | ||
| CREATE INDEX IF NOT EXISTS idx_stores_lat_lng | ||
| ON stores (latitude, longitude) | ||
| WHERE is_deleted = false; | ||
|
|
||
| -- ๊ฒ์ฆ | ||
| -- SELECT pg_typeof(location) FROM stores LIMIT 1; -- geography ์ด์ด์ผ ์ ์ | ||
| -- SELECT COUNT(*) FROM stores WHERE location IS NULL; -- 0 ์ด์ด์ผ ์ ์ | ||
| -- SELECT indexname FROM pg_indexes WHERE tablename = 'stores' AND indexname LIKE 'idx_stores%'; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| package com.catchtable.global.config; | ||
|
|
||
| import org.springframework.cache.annotation.EnableCaching; | ||
| import org.springframework.context.annotation.Bean; | ||
| import org.springframework.context.annotation.Configuration; | ||
| import org.springframework.data.redis.cache.RedisCacheConfiguration; | ||
| import org.springframework.data.redis.cache.RedisCacheManager; | ||
| import org.springframework.data.redis.connection.RedisConnectionFactory; | ||
| import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer; | ||
| import org.springframework.data.redis.serializer.RedisSerializationContext; | ||
| import org.springframework.data.redis.serializer.StringRedisSerializer; | ||
|
|
||
| import java.time.Duration; | ||
| import java.util.Map; | ||
|
|
||
| @EnableCaching | ||
| @Configuration | ||
| public class CacheConfig { | ||
|
|
||
| @Bean | ||
| public RedisCacheManager cacheManager(RedisConnectionFactory connectionFactory) { | ||
| RedisCacheConfiguration defaults = RedisCacheConfiguration.defaultCacheConfig() | ||
| .serializeKeysWith(RedisSerializationContext.SerializationPair.fromSerializer(new StringRedisSerializer())) | ||
| .serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(new GenericJackson2JsonRedisSerializer())) | ||
| .disableCachingNullValues(); | ||
|
|
||
| Map<String, RedisCacheConfiguration> cacheConfigs = Map.of( | ||
| "popularStores", defaults.entryTtl(Duration.ofMinutes(5)) | ||
| ); | ||
|
|
||
| return RedisCacheManager.builder(connectionFactory) | ||
| .cacheDefaults(defaults.entryTtl(Duration.ofMinutes(10))) | ||
| .withInitialCacheConfigurations(cacheConfigs) | ||
| .build(); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -14,17 +14,28 @@ | |||||||
| import jakarta.persistence.GeneratedValue; | ||||||||
| import jakarta.persistence.GenerationType; | ||||||||
| import jakarta.persistence.Id; | ||||||||
| import jakarta.persistence.Index; | ||||||||
| import jakarta.persistence.JoinColumn; | ||||||||
| import jakarta.persistence.ManyToOne; | ||||||||
| import jakarta.persistence.PrePersist; | ||||||||
| import jakarta.persistence.PreUpdate; | ||||||||
| import jakarta.persistence.Table; | ||||||||
| import lombok.AccessLevel; | ||||||||
| import lombok.Builder; | ||||||||
| import lombok.Getter; | ||||||||
| import lombok.NoArgsConstructor; | ||||||||
|
|
||||||||
| @Getter | ||||||||
| @Entity | ||||||||
| @Table( | ||||||||
| name = "reservations", | ||||||||
| indexes = { | ||||||||
| @Index(name = "idx_reservation_user_id", columnList = "user_id"), | ||||||||
| @Index(name = "idx_reservation_user_status", columnList = "user_id, status"), | ||||||||
|
Comment on lines
+33
to
+34
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ๋ณตํฉ ์ธ๋ฑ์ค
Suggested change
|
||||||||
| @Index(name = "idx_reservation_remain_id", columnList = "remain_id"), | ||||||||
| @Index(name = "idx_reservation_status", columnList = "status") | ||||||||
| } | ||||||||
| ) | ||||||||
| @NoArgsConstructor(access = AccessLevel.PROTECTED) | ||||||||
| public class Reservation { | ||||||||
|
|
||||||||
|
|
||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BookmarkRepository์
softDeleteAllByFolderId๋ฉ์๋์๋@Modifying(clearAutomatically = true)์ค์ ์ด ์ ์ฉ๋์ด ์์ต๋๋ค. ์ด๋ก ์ธํด ๋ฒํฌ ์ ๋ฐ์ดํธ ์ฟผ๋ฆฌ ์คํ ์งํ ์์์ฑ ์ปจํ ์คํธ(Persistence Context)๊ฐ ์์ ํ ๋น์์ง๊ฒ(clear) ๋๋ฉฐ, ์ด์ ์ ์กฐํํ๋folder์ํฐํฐ๋ ์ค์์(Detached) ์ํ๊ฐ ๋ฉ๋๋ค.๋ฐ๋ผ์ ๊ทธ ์ดํ์ ํธ์ถ๋๋
folder.softDelete()๋ ์ค์์ ์ํ์ ๊ฐ์ฒด ํ๋๋ง ๋ณ๊ฒฝํ ๋ฟ, ํธ๋์ญ์ ์ปค๋ฐ ์์ ์ ๋ฐ์ดํฐ๋ฒ ์ด์ค๋ก ๋ณ๊ฒฝ ์ฌํญ์ด ๋ฐ์(Flush)๋์ง ์์ ํด๋ ์์ฒด๊ฐ ์ญ์ ๋์ง ์๋ ์ฌ๊ฐํ ๋ฒ๊ทธ๊ฐ ๋ฐ์ํฉ๋๋ค.์ด๋ฅผ ํด๊ฒฐํ๊ธฐ ์ํด
folder.softDelete()๋ฅผ ๋ฒํฌ ์ญ์ ๋ฉ์๋ ํธ์ถ ์ ์ ์คํํ๋๋ก ์์๋ฅผ ๋ณ๊ฒฝํด์ผ ํฉ๋๋ค. ์ด๋ ๊ฒ ํ๋ฉด ๋ฒํฌ ์ฟผ๋ฆฌ๊ฐ ์คํ๋๊ธฐ ์ ํ์ด๋ฒ๋ค์ดํธ์ ์๋ ํ๋ฌ์(Auto-Flush)์ ์ํด ํด๋์ ์ญ์ ์ํ๊ฐ DB์ ๋จผ์ ๋ฐ์๋ ํ ๋ฒํฌ ์ญ์ ๊ฐ ์์ ํ๊ฒ ์งํ๋ฉ๋๋ค.