Skip to content

Commit

Permalink
Merge pull request #86 from Korea-Certified-Store/refactor/refactor-s…
Browse files Browse the repository at this point in the history
…torecertification-api(#85)

가게 조회 API 성능 개선 #85)
  • Loading branch information
sungjindev authored Feb 7, 2024
2 parents 233d5c5 + 25a33d2 commit 92c51bc
Show file tree
Hide file tree
Showing 10 changed files with 185 additions and 154 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

import static com.nainga.nainga.domain.store.application.GoogleMapMethods.*;

Expand Down Expand Up @@ -76,10 +78,10 @@ public void createAllGoodPriceStores(String fileName) {

//WKTReader Parse exception에 대한 처리를 위한 try-catch문
try {
Set<StoreRegularOpeningHours> regularOpeningHours;
Set<String> weekdayDescriptions = new LinkedHashSet<>();
Set<String> localPhotosList = new LinkedHashSet<>();
Set<String> googlePhotosList = new LinkedHashSet<>();
List<StoreRegularOpeningHours> regularOpeningHours;
List<String> weekdayDescriptions = new ArrayList<>();
List<String> localPhotosList = new ArrayList<>();
List<String> googlePhotosList = new ArrayList<>();
String phoneNumber = null;
String primaryTypeDisplayName = null;

Expand Down Expand Up @@ -111,23 +113,15 @@ public void createAllGoodPriceStores(String fileName) {

if (!googlePhotosList.isEmpty()) { //가장 첫 번째 사진만 실제로 다운로드까지 진행하고 나머지는 나중에 쓸 용도로 googlePhotosList에 저장
if (currentProfile.equals("dev") || currentProfile.equals("prod")) {
byte[] googleMapPlacesImageAsBytes = getGoogleMapPlacesImageAsBytes(googlePhotosList.stream().findFirst().get(), googleApiKey);
byte[] googleMapPlacesImageAsBytes = getGoogleMapPlacesImageAsBytes(googlePhotosList.get(0), googleApiKey);
if (googleMapPlacesImageAsBytes != null) {
String gcsPath = gcsService.uploadImage(googleMapPlacesImageAsBytes);
localPhotosList.add(gcsPath);
Iterator<String> iterator = googlePhotosList.iterator();
if (iterator.hasNext()) { //googlePhotosList에서 가장 첫 번째 원소를 제거
iterator.next();
iterator.remove();
}
googlePhotosList.remove(0);
}
} else { //local이나 test 시
localPhotosList.add(getGoogleMapPlacesImageToLocal(googlePhotosList.stream().findFirst().get(), googleApiKey));
Iterator<String> iterator = googlePhotosList.iterator();
if (iterator.hasNext()) { //googlePhotosList에서 가장 첫 번째 원소를 제거
iterator.next();
iterator.remove();
}
localPhotosList.add(getGoogleMapPlacesImageToLocal(googlePhotosList.get(0), googleApiKey));
googlePhotosList.remove(0);
}
}

Expand Down Expand Up @@ -245,10 +239,10 @@ public CreateDividedGoodPriceStoresResponse createDividedGoodPriceStores(String

//WKTReader Parse exception에 대한 처리를 위한 try-catch문
try {
Set<StoreRegularOpeningHours> regularOpeningHours;
Set<String> weekdayDescriptions = new LinkedHashSet<>();
Set<String> localPhotosList = new LinkedHashSet<>();
Set<String> googlePhotosList = new LinkedHashSet<>();
List<StoreRegularOpeningHours> regularOpeningHours;
List<String> weekdayDescriptions = new ArrayList<>();
List<String> localPhotosList = new ArrayList<>();
List<String> googlePhotosList = new ArrayList<>();
String phoneNumber = null;
String primaryTypeDisplayName = null;

Expand Down Expand Up @@ -287,25 +281,17 @@ public CreateDividedGoodPriceStoresResponse createDividedGoodPriceStores(String
}
//돈이 충분히 있으면,
if (currentProfile.equals("dev") || currentProfile.equals("prod")) {
byte[] googleMapPlacesImageAsBytes = getGoogleMapPlacesImageAsBytes(googlePhotosList.stream().findFirst().get(), googleApiKey);
byte[] googleMapPlacesImageAsBytes = getGoogleMapPlacesImageAsBytes(googlePhotosList.get(0), googleApiKey);
if (googleMapPlacesImageAsBytes != null) {
String gcsPath = gcsService.uploadImage(googleMapPlacesImageAsBytes);
localPhotosList.add(gcsPath);
Iterator<String> iterator = googlePhotosList.iterator();
if (iterator.hasNext()) { //googlePhotosList에서 가장 첫 번째 원소를 제거
iterator.next();
iterator.remove();
}
googlePhotosList.remove(0);
//소비한 비용 반영
dollars -= 0.007;
}
} else { //local이나 test 시
localPhotosList.add(getGoogleMapPlacesImageToLocal(googlePhotosList.stream().findFirst().get(), googleApiKey)); //가장 첫 번째 사진만 실제로 다운로드까지 진행하고 나머지는 나중에 쓸 용도로 googlePhotosList에 저장
Iterator<String> iterator = googlePhotosList.iterator();
if (iterator.hasNext()) { //googlePhotosList에서 가장 첫 번째 원소를 제거
iterator.next();
iterator.remove();
}
localPhotosList.add(getGoogleMapPlacesImageToLocal(googlePhotosList.get(0), googleApiKey)); //가장 첫 번째 사진만 실제로 다운로드까지 진행하고 나머지는 나중에 쓸 용도로 googlePhotosList에 저장
googlePhotosList.remove(0);
//소비한 비용 반영
dollars -= 0.007;
}
Expand Down Expand Up @@ -394,8 +380,8 @@ public CreateDividedGoodPriceStoresResponse createDividedGoodPriceStores(String

//Google Map API에서 제공해주는 영업 시간 정보가 periods와 weekdayDescriptions 방식이 있는데, 기존에 구조화된 periods를 사용했었지만 데이터가 깨져있는 경우가 종종 있어서,
//조금 더 안정적인 weekdayDescriptions으로 데이터를 받아오고 직접 파싱해서 periods 식으로 변환하여 저장하기 위함
public Set<StoreRegularOpeningHours> parseWeekdayDescriptions(Set<String> weekdayDescriptions) {
Set<StoreRegularOpeningHours> storeRegularOpeningHoursList = new LinkedHashSet<>();
public List<StoreRegularOpeningHours> parseWeekdayDescriptions(List<String> weekdayDescriptions) {
List<StoreRegularOpeningHours> storeRegularOpeningHoursList = new ArrayList<>();

for (String weekdayDescription : weekdayDescriptions) {
weekdayDescription = weekdayDescription.replace(",", " "); //,는 제거
Expand Down Expand Up @@ -505,3 +491,4 @@ public Set<StoreRegularOpeningHours> parseWeekdayDescriptions(Set<String> weekda




Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

import static com.nainga.nainga.domain.store.application.GoogleMapMethods.*;

Expand Down Expand Up @@ -77,10 +79,10 @@ public void createAllMobeomStores(String fileName) {

//WKTReader Parse exception에 대한 처리를 위한 try-catch문
try {
Set<StoreRegularOpeningHours> regularOpeningHours;
Set<String> weekdayDescriptions = new LinkedHashSet<>();
Set<String> localPhotosList = new LinkedHashSet<>();
Set<String> googlePhotosList = new LinkedHashSet<>();
List<StoreRegularOpeningHours> regularOpeningHours;
List<String> weekdayDescriptions = new ArrayList<>();
List<String> localPhotosList = new ArrayList<>();
List<String> googlePhotosList = new ArrayList<>();
String phoneNumber = null;
String primaryTypeDisplayName = null;

Expand Down Expand Up @@ -112,23 +114,15 @@ public void createAllMobeomStores(String fileName) {

if (!googlePhotosList.isEmpty()) { //가장 첫 번째 사진만 실제로 다운로드까지 진행하고 나머지는 나중에 쓸 용도로 googlePhotosList에 저장
if (currentProfile.equals("dev") || currentProfile.equals("prod")) {
byte[] googleMapPlacesImageAsBytes = getGoogleMapPlacesImageAsBytes(googlePhotosList.stream().findFirst().get(), googleApiKey);
byte[] googleMapPlacesImageAsBytes = getGoogleMapPlacesImageAsBytes(googlePhotosList.get(0), googleApiKey);
if (googleMapPlacesImageAsBytes != null) {
String gcsPath = gcsService.uploadImage(googleMapPlacesImageAsBytes);
localPhotosList.add(gcsPath);
Iterator<String> iterator = googlePhotosList.iterator();
if (iterator.hasNext()) { //googlePhotosList에서 가장 첫 번째 원소를 제거
iterator.next();
iterator.remove();
}
googlePhotosList.remove(0);
}
} else { //local이나 test 시
localPhotosList.add(getGoogleMapPlacesImageToLocal(googlePhotosList.stream().findFirst().get(), googleApiKey));
Iterator<String> iterator = googlePhotosList.iterator();
if (iterator.hasNext()) { //googlePhotosList에서 가장 첫 번째 원소를 제거
iterator.next();
iterator.remove();
}
localPhotosList.add(getGoogleMapPlacesImageToLocal(googlePhotosList.get(0), googleApiKey));
googlePhotosList.remove(0);
}
}

Expand Down Expand Up @@ -246,10 +240,10 @@ public CreateDividedMobeomStoresResponse createDividedMobeomStores(String fileNa

//WKTReader Parse exception에 대한 처리를 위한 try-catch문
try {
Set<StoreRegularOpeningHours> regularOpeningHours;
Set<String> weekdayDescriptions = new LinkedHashSet<>();
Set<String> localPhotosList = new LinkedHashSet<>();
Set<String> googlePhotosList = new LinkedHashSet<>();
List<StoreRegularOpeningHours> regularOpeningHours;
List<String> weekdayDescriptions = new ArrayList<>();
List<String> localPhotosList = new ArrayList<>();
List<String> googlePhotosList = new ArrayList<>();
String phoneNumber = null;
String primaryTypeDisplayName = null;

Expand Down Expand Up @@ -288,25 +282,17 @@ public CreateDividedMobeomStoresResponse createDividedMobeomStores(String fileNa
}
//돈이 충분히 있으면,
if (currentProfile.equals("dev") || currentProfile.equals("prod")) {
byte[] googleMapPlacesImageAsBytes = getGoogleMapPlacesImageAsBytes(googlePhotosList.stream().findFirst().get(), googleApiKey);
byte[] googleMapPlacesImageAsBytes = getGoogleMapPlacesImageAsBytes(googlePhotosList.get(0), googleApiKey);
if (googleMapPlacesImageAsBytes != null) {
String gcsPath = gcsService.uploadImage(googleMapPlacesImageAsBytes);
localPhotosList.add(gcsPath);
Iterator<String> iterator = googlePhotosList.iterator();
if (iterator.hasNext()) { //googlePhotosList에서 가장 첫 번째 원소를 제거
iterator.next();
iterator.remove();
}
googlePhotosList.remove(0);
//소비한 비용 반영
dollars -= 0.007;
}
} else { //local이나 test 시
localPhotosList.add(getGoogleMapPlacesImageToLocal(googlePhotosList.stream().findFirst().get(), googleApiKey)); //가장 첫 번째 사진만 실제로 다운로드까지 진행하고 나머지는 나중에 쓸 용도로 googlePhotosList에 저장
Iterator<String> iterator = googlePhotosList.iterator();
if (iterator.hasNext()) { //googlePhotosList에서 가장 첫 번째 원소를 제거
iterator.next();
iterator.remove();
}
localPhotosList.add(getGoogleMapPlacesImageToLocal(googlePhotosList.get(0), googleApiKey)); //가장 첫 번째 사진만 실제로 다운로드까지 진행하고 나머지는 나중에 쓸 용도로 googlePhotosList에 저장
googlePhotosList.remove(0);
//소비한 비용 반영
dollars -= 0.007;
}
Expand Down Expand Up @@ -395,8 +381,8 @@ public CreateDividedMobeomStoresResponse createDividedMobeomStores(String fileNa

//Google Map API에서 제공해주는 영업 시간 정보가 periods와 weekdayDescriptions 방식이 있는데, 기존에 구조화된 periods를 사용했었지만 데이터가 깨져있는 경우가 종종 있어서,
//조금 더 안정적인 weekdayDescriptions으로 데이터를 받아오고 직접 파싱해서 periods 식으로 변환하여 저장하기 위함
public Set<StoreRegularOpeningHours> parseWeekdayDescriptions(Set<String> weekdayDescriptions) {
Set<StoreRegularOpeningHours> storeRegularOpeningHoursList = new LinkedHashSet<>();
public List<StoreRegularOpeningHours> parseWeekdayDescriptions(List<String> weekdayDescriptions) {
List<StoreRegularOpeningHours> storeRegularOpeningHoursList = new ArrayList<>();

for (String weekdayDescription : weekdayDescriptions) {
weekdayDescription = weekdayDescription.replace(",", " "); //,는 제거
Expand Down Expand Up @@ -503,3 +489,4 @@ public Set<StoreRegularOpeningHours> parseWeekdayDescriptions(Set<String> weekda
return storeRegularOpeningHoursList;
}
}

Loading

0 comments on commit 92c51bc

Please sign in to comment.