@@ -23,7 +23,6 @@ public abstract class BatchService {
23
23
private final CategoryRepository categoryRepository ;
24
24
private final LocationRepository locationRepository ;
25
25
26
- @ Transactional
27
26
public void batch (List <? extends ApiResponse > apiResponses ) {
28
27
Category category = categoryRepository .findByName (apiResponses .get (0 ).getCategory ())
29
28
.orElseGet (() -> categoryRepository .save (Category .create (apiResponses .get (0 ).getCategory ())));
@@ -32,31 +31,33 @@ public void batch(List<? extends ApiResponse> apiResponses) {
32
31
.collect (Collectors .toMap (CatcherItem ::getItemHashValue , Function .identity ()));
33
32
34
33
List <CatcherItem > deleteItems = new ArrayList <>();
34
+ List <CatcherItem > saveItems = new ArrayList <>();
35
35
36
36
List <CatcherItem > catcherItems = apiResponses .stream ()
37
37
.filter (apiResponse -> {
38
38
String hashKey = hashString (apiResponse );
39
39
if (itemMap .containsKey (hashKey )) {
40
40
if (isExpired (apiResponse .getEndAt ())) {
41
41
deleteItems .add (itemMap .get (hashKey ));
42
- itemMap .remove (hashKey );
43
- return false ;
44
42
}
45
43
if (isContentChanged (itemMap .get (hashKey ), apiResponse )) {
46
- return true ;
44
+ CatcherItem e = itemMap .get (hashKey );
45
+ // e.changeContent(dsfasfaf,dadasd); ... 요기에 바꾸는 로직 추가
46
+ saveItems .add (e );
47
47
}
48
+ return false ;
48
49
} else {
49
- if (isExpired (apiResponse .getEndAt ())) {
50
+ if (isExpired (apiResponse .getEndAt ())) {
50
51
return false ;
51
52
}
53
+ return true ;
52
54
}
53
- return true ;
54
55
})
55
56
.map (apiResponse -> apiResponseToCatcherItem (apiResponse , category , getLocation (apiResponse )))
56
57
.toList ();
57
58
58
- if (!catcherItems .isEmpty ()) {
59
- catcherItemRepository .saveAll (catcherItems );
59
+ if (!saveItems .isEmpty ()) {
60
+ catcherItemRepository .saveAll (saveItems );
60
61
}
61
62
62
63
if (!deleteItems .isEmpty ()) {
0 commit comments