Skip to content

Commit

Permalink
fix: Remove array fields not required for service feature (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
nusuy committed Sep 26, 2023
1 parent c93dace commit 1342de4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.cubix.extsearchbatch.service;

import com.cubix.extsearchbatch.dto.NaverRawNewsItemDto;
import com.cubix.extsearchbatch.entity.NewsEntity;
import com.cubix.extsearchbatch.entity.NewsRepository;
import com.cubix.extsearchbatch.exception.OpenApiRequestException;
import com.cubix.extsearchbatch.exception.OpenApiResponseException;
Expand All @@ -23,8 +22,6 @@ public class DataUpdateService {
private final NewsRepository newsRepository;
private final NewsDataReader newsDataReader;
private final NewsDataWriter newsDataWriter;
private ArrayList<NaverRawNewsItemDto> rawData;
private ArrayList<NewsEntity> resultData;

@PostConstruct
public void onStartup() {
Expand All @@ -33,8 +30,6 @@ public void onStartup() {

@Scheduled(cron = "0 0 3 * * *", zone = "Asia/Seoul")
public void updateNewsData() {
rawData = new ArrayList<>();
resultData = new ArrayList<>();
log.info("Naver news data request started. --" + LocalDateTime.now());

final int DISPLAY_DEF = 100;
Expand All @@ -58,15 +53,14 @@ public void updateNewsData() {

// Get data
ArrayList<NaverRawNewsItemDto> items = newsDataReader.get(display, start).getItems();
rawData.addAll(items);

// Write data
if (isEmptyDB) {
// DB is empty (no need to validate)
resultData.addAll(newsDataWriter.writeWithoutValidation(items));
newsDataWriter.writeWithoutValidation(items);
} else {
// DB is not empty (validation required)
resultData.addAll(newsDataWriter.writeWithValidation(items));
newsDataWriter.writeWithValidation(items);
}
}

Expand All @@ -79,12 +73,4 @@ public void updateNewsData() {
log.error("Naver API response status <" + e.getStatusCode().value() + ">: " + e.getMessage());
}
}

public ArrayList<NaverRawNewsItemDto> getRawData() {
return rawData;
}

public ArrayList<NewsEntity> getResultData() {
return resultData;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public NewsEntity getDuplicateData(NaverRawNewsItemDto naverRawNewsItemDto) {
}

@Transactional
public ArrayList<NewsEntity> writeWithValidation(ArrayList<NaverRawNewsItemDto> items) {
public void writeWithValidation(ArrayList<NaverRawNewsItemDto> items) {
ArrayList<NewsEntity> validatedItems = new ArrayList<>();

for (NaverRawNewsItemDto rawNewsItemDto : items) {
Expand All @@ -42,11 +42,9 @@ public ArrayList<NewsEntity> writeWithValidation(ArrayList<NaverRawNewsItemDto>

// Save data
newsRepository.saveAll(validatedItems);

return validatedItems;
}

public ArrayList<NewsEntity> writeWithoutValidation(ArrayList<NaverRawNewsItemDto> items) {
public void writeWithoutValidation(ArrayList<NaverRawNewsItemDto> items) {
ArrayList<NewsEntity> resultList = new ArrayList<>();

for (NaverRawNewsItemDto rawNewsItemDto : items) {
Expand All @@ -55,7 +53,5 @@ public ArrayList<NewsEntity> writeWithoutValidation(ArrayList<NaverRawNewsItemDt

// Save data
newsRepository.saveAll(resultList);

return resultList;
}
}

0 comments on commit 1342de4

Please sign in to comment.