Skip to content

Commit 5c99bc0

Browse files
committed
suport load matrix by flow id list
1 parent 15b8481 commit 5c99bc0

File tree

4 files changed

+30
-9
lines changed

4 files changed

+30
-9
lines changed

core/src/main/java/com/flowci/core/flow/controller/MatrixController.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
import java.time.Instant;
3030
import java.time.temporal.ChronoUnit;
31+
import java.util.Collection;
3132
import java.util.List;
3233

3334
/**
@@ -57,6 +58,11 @@ public MatrixItem total(@PathVariable String name, @RequestParam String t) {
5758
return matrixService.get(flow.getId(), t, MatrixItem.ZERO_DAY);
5859
}
5960

61+
@PostMapping("/matrix/batch/total")
62+
public List<MatrixItem> batchTotal(@RequestParam String t, @RequestBody Collection<String> flowIdList) {
63+
return matrixService.list(flowIdList, t, MatrixItem.ZERO_DAY);
64+
}
65+
6066
@GetMapping("/{name}/matrix")
6167
public List<MatrixItem> list(@PathVariable String name,
6268
@RequestParam(required = false) String t,

core/src/main/java/com/flowci/core/flow/dao/StatsItemDao.java renamed to core/src/main/java/com/flowci/core/flow/dao/MatrixItemDao.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,15 @@
2222
import org.springframework.data.mongodb.repository.Query;
2323
import org.springframework.stereotype.Repository;
2424

25+
import java.util.Collection;
2526
import java.util.List;
2627
import java.util.Optional;
2728

2829
/**
2930
* @author yang
3031
*/
3132
@Repository
32-
public interface StatsItemDao extends MongoRepository<MatrixItem, String> {
33+
public interface MatrixItemDao extends MongoRepository<MatrixItem, String> {
3334

3435
@Query("{'flowId':?0, 'type': ?1, 'day' : {$gte : ?2, $lte : ?3}}")
3536
List<MatrixItem> findByFlowIdAndTypeDayBetween(String flowId, String type, int dayGT, int dayLT, Sort sort);
@@ -39,5 +40,7 @@ public interface StatsItemDao extends MongoRepository<MatrixItem, String> {
3940

4041
Optional<MatrixItem> findByFlowIdAndDayAndType(String flowId, int day, String type);
4142

43+
List<MatrixItem> findAllByFlowIdInAndDayAndType(Collection<String> flowIds, int day, String type);
44+
4245
void deleteByFlowId(String flowId);
4346
}

core/src/main/java/com/flowci/core/flow/service/MatrixService.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import com.flowci.core.flow.domain.MatrixCounter;
2121
import com.flowci.core.flow.domain.MatrixItem;
2222
import com.flowci.core.flow.domain.MatrixType;
23+
24+
import java.util.Collection;
2325
import java.util.List;
2426
import java.util.Map;
2527

@@ -45,6 +47,11 @@ public interface MatrixService {
4547
*/
4648
List<MatrixItem> list(String flowId, String type, int fromDay, int toDay);
4749

50+
/**
51+
* List matrix items on specific day by flow id list
52+
*/
53+
List<MatrixItem> list(Collection<String> flowIdList, String type, int day);
54+
4855
/**
4956
* Get statistic item
5057
*/

core/src/main/java/com/flowci/core/flow/service/MatrixServiceImpl.java

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import com.fasterxml.jackson.core.type.TypeReference;
2020
import com.fasterxml.jackson.databind.ObjectMapper;
2121
import com.flowci.core.common.helper.DateHelper;
22-
import com.flowci.core.flow.dao.StatsItemDao;
22+
import com.flowci.core.flow.dao.MatrixItemDao;
2323
import com.flowci.core.flow.domain.*;
2424
import com.flowci.core.flow.event.FlowDeletedEvent;
2525
import com.flowci.core.job.domain.Job;
@@ -58,7 +58,7 @@ public class MatrixServiceImpl implements MatrixService {
5858
private ObjectMapper objectMapper;
5959

6060
@Autowired
61-
private StatsItemDao statsItemDao;
61+
private MatrixItemDao matrixItemDao;
6262

6363
@Autowired
6464
private YmlService ymlService;
@@ -102,7 +102,7 @@ public void onJobStatusChange(JobStatusChangeEvent event) {
102102

103103
@EventListener
104104
public void onFlowDelete(FlowDeletedEvent event) {
105-
statsItemDao.deleteByFlowId(event.getFlow().getId());
105+
matrixItemDao.deleteByFlowId(event.getFlow().getId());
106106
}
107107

108108
@Override
@@ -139,15 +139,20 @@ public List<MatrixItem> list(String flowId, String type, int fromDay, int toDay)
139139
Sort sort = Sort.by(Sort.Direction.ASC, "day");
140140

141141
if (StringHelper.hasValue(type)) {
142-
return statsItemDao.findByFlowIdAndTypeDayBetween(flowId, type, fromDay, toDay, sort);
142+
return matrixItemDao.findByFlowIdAndTypeDayBetween(flowId, type, fromDay, toDay, sort);
143143
}
144144

145-
return statsItemDao.findByFlowIdDayBetween(flowId, fromDay, toDay, sort);
145+
return matrixItemDao.findByFlowIdDayBetween(flowId, fromDay, toDay, sort);
146+
}
147+
148+
@Override
149+
public List<MatrixItem> list(Collection<String> flowIdList, String type, int day) {
150+
return matrixItemDao.findAllByFlowIdInAndDayAndType(flowIdList, day, type);
146151
}
147152

148153
@Override
149154
public MatrixItem get(String flowId, String type, int day) {
150-
Optional<MatrixItem> item = statsItemDao.findByFlowIdAndDayAndType(flowId, day, type);
155+
Optional<MatrixItem> item = matrixItemDao.findByFlowIdAndDayAndType(flowId, day, type);
151156
if (item.isPresent()) {
152157
return item.get();
153158
}
@@ -168,13 +173,13 @@ public MatrixItem add(String flowId, int day, String type, MatrixCounter counter
168173
dayItem.setTotal(totalItem.getCounter());
169174
dayItem.setNumOfTotal(totalItem.getNumOfToday());
170175

171-
statsItemDao.saveAll(Arrays.asList(dayItem, totalItem));
176+
matrixItemDao.saveAll(Arrays.asList(dayItem, totalItem));
172177
return dayItem;
173178
}
174179
}
175180

176181
private MatrixItem getItem(String flowId, int day, String type) {
177-
Optional<MatrixItem> optional = statsItemDao.findByFlowIdAndDayAndType(flowId, day, type);
182+
Optional<MatrixItem> optional = matrixItemDao.findByFlowIdAndDayAndType(flowId, day, type);
178183

179184
return optional.orElseGet(() -> new MatrixItem()
180185
.setDay(day)

0 commit comments

Comments
 (0)