Skip to content

Commit

Permalink
refactor: 식품 조회시 top3 diet tag 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
koo995 committed Oct 22, 2024
1 parent 8014928 commit 68c936a
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ public class ProductSearchResponse {
private final String productName;
private final String productCorp;
private final Integer reviewCount;
private final Double reviewAvgRating;
private final String top3_diet_tag_names;
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ public Page<ProductSearchResponse> findFullTextSearch(String keyword, Pageable p
Integer total = getTotalCount(keyword);

String sql = "SELECT " +
"p.product_id, p.product_name, p.product_corp, (SELECT COUNT(*) FROM review r where r.product_id = p.product_id) AS review_count " +
"p.product_id, p.product_name, p.product_corp, " +
"(SELECT COUNT(*) FROM review r WHERE r.product_id = p.product_id) AS review_count, " +
"(SELECT AVG(r.rating) FROM review r WHERE r.product_id = p.product_id) AS review_avg_rating, " +
"(SELECT GROUP_CONCAT(diet_tag_name) FROM (SELECT diet_tag_name FROM product_diet_tag pdt where pdt.product_id = p.product_id GROUP BY diet_tag_name ORDER BY COUNT(diet_tag_name) DESC LIMIT 3) AS top3_diet_tag) AS top3_diet_tag_names " +
"FROM product p " +
"WHERE MATCH (p.product_name, p.product_corp) AGAINST (:keyword)" +
"LIMIT :offset, :limit";
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ logging:
org:
springframework:
jdbc:
core: debug
core: error

---
spring:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
// @Autowired
// private JdbcTemplate jdbcTemplate;
//
// private final int batchSize = 1000;
// private final int threadCount = 5;
// private final int batchSize = 5000;
// private final int threadCount = 10;
// private final int totalDataCount = 20000000;
// private final Random random = new Random();
//
// private final String productDietTagSQL = "INSERT INTO product_diet_tag (product_id, diet_tag_id, created_at, updated_at) VALUES (?, ?, ?, ?)";
// private final String productDietTagSQL = "INSERT INTO product_diet_tag (product_id, diet_tag_id, diet_tag_name, created_at, updated_at) VALUES (?, ?, ?, ?, ?)";
// private final String[] diet_tag_names = {"저칼로리", "저탄수화물", "무탄수화물", "저단백질", "고단백질", "무설탕", "저지방", "고지방", "저탄고지", "기토제닉"};
//
// @Test
// public void insertProductDataInParallel() throws InterruptedException {
Expand All @@ -31,11 +33,12 @@
// List<Object[]> batchArgs = new ArrayList<>();
//
// for (int i = start; i <= end; i++) {
// int productId = (i % 8) * 100000 + i % 100000;
// int productId = random.nextInt(1000000);
// int dietTagId = i % 10 + 1;
// String dietTagName = diet_tag_names[dietTagId - 1];
// String createdAt = "2024-09-01 00:00:00";
// String updatedAt = "2024-09-01 00:00:00";
// batchArgs.add(new Object[]{productId, dietTagId, createdAt, updatedAt});
// batchArgs.add(new Object[]{productId, dietTagId, dietTagName, createdAt, updatedAt});
//
// if (batchArgs.size() % batchSize == 0) {
// jdbcTemplate.batchUpdate(sql, batchArgs);
Expand Down
19 changes: 5 additions & 14 deletions src/test/java/flab/nutridiary/dummy/InsertReviewDummy.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,15 @@
package flab.nutridiary.dummy;

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.jdbc.core.JdbcTemplate;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

//@SpringBootTest
//public class InsertReviewDummy {
// @Autowired
// private JdbcTemplate jdbcTemplate;
//
// private final int batchSize = 1000;
// private final int threadCount = 5;
// private final int batchSize = 5000;
// private final int threadCount = 10;
// private final int totalDataCount = 10000000;
// private final Random random = new Random();
//
//
// private final String reviewSQL = "INSERT INTO review (product_id, member_id, content, rating, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?)";
//
Expand All @@ -42,7 +33,7 @@
// List<Object[]> batchArgs = new ArrayList<>();
//
// for (int i = start; i <= end; i++) {
// int productId = (i % 8) * 100000 + i % 100000;
// int productId = random.nextInt(1000000);
// int memberId = i;
// String content = i + "content " + i;
// int rating = i % 5 + 1;
Expand Down

0 comments on commit 68c936a

Please sign in to comment.