Skip to content

Commit f3d570b

Browse files
committed
add refresh branches cache and list branches cache
1 parent 5553baa commit f3d570b

File tree

4 files changed

+28
-9
lines changed

4 files changed

+28
-9
lines changed

platform-api/src/main/java/com/flow/platform/api/controller/FlowController.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616

1717
package com.flow.platform.api.controller;
1818

19-
import com.flow.platform.api.domain.permission.Actions;
2019
import com.flow.platform.api.domain.node.Flow;
2120
import com.flow.platform.api.domain.node.Node;
21+
import com.flow.platform.api.domain.permission.Actions;
2222
import com.flow.platform.api.domain.request.ListParam;
2323
import com.flow.platform.api.domain.response.BooleanValue;
2424
import com.flow.platform.api.domain.user.User;
@@ -246,11 +246,15 @@ public BooleanValue isFlowNameExist() {
246246
* ]
247247
*/
248248
@GetMapping("/{root}/branches")
249-
public List<String> listBranches() {
249+
public List<String> listBranches(@RequestParam(required = false) Boolean refresh) {
250250
Node root = nodeService.find(currentNodePath.get());
251-
return gitService.branches(root);
251+
if (refresh != null && refresh == true) {
252+
return gitService.refreshBranches(root);
253+
}
254+
return gitService.listBranches(root);
252255
}
253256

257+
254258
/**
255259
* @api {get} /flows/:root/tags List Tags
256260
* @apiParam {String} root flow node name
@@ -415,7 +419,7 @@ public Node createFromYml(@RequestBody String yml) {
415419
*/
416420
@PostMapping("/{root}/users/auth")
417421
@WebSecurity(action = Actions.FLOW_AUTH)
418-
public List<User> flowAuthUsers(@RequestBody ListParam<String> listParam){
422+
public List<User> flowAuthUsers(@RequestBody ListParam<String> listParam) {
419423
return nodeService.authUsers(listParam.getArrays(), currentNodePath.get());
420424
}
421425
}

platform-api/src/main/java/com/flow/platform/api/service/GitService.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,12 @@ interface ProgressListener {
6363
/**
6464
* Fetch branches from git repo
6565
*/
66-
List<String> branches(Node node);
66+
List<String> listBranches(Node node);
67+
68+
/**
69+
* refresh branches
70+
*/
71+
List<String> refreshBranches(Node node);
6772

6873
/**
6974
* Fetch tags from git repo

platform-api/src/main/java/com/flow/platform/api/service/GitServiceImpl.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import org.eclipse.jgit.lib.Ref;
4848
import org.springframework.beans.factory.annotation.Autowired;
4949
import org.springframework.cache.CacheManager;
50+
import org.springframework.cache.annotation.CachePut;
5051
import org.springframework.cache.annotation.Cacheable;
5152
import org.springframework.stereotype.Service;
5253

@@ -90,9 +91,18 @@ public String clone(Node node, String filePath, ProgressListener progressListene
9091
return fetch(client, filePath);
9192
}
9293

93-
@Override
94-
@Cacheable(value = "branches")
95-
public List<String> branches(Node node) {
94+
95+
@Cacheable(value = "branches", key = "#node.getPath()")
96+
public List<String> listBranches(Node node) {
97+
return fetchBranches(node);
98+
}
99+
100+
@CachePut(value = "branches", key = "#node.getPath()")
101+
public List<String> refreshBranches(Node node) {
102+
return fetchBranches(node);
103+
}
104+
105+
private List<String> fetchBranches(Node node) {
96106
GitClient client = gitClientInstance(node);
97107
try {
98108
Collection<Ref> branches = client.branches();

platform-api/src/test/java/com/flow/platform/api/test/service/GitServiceTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public void onFinish() {
9999

100100
@Test
101101
public void should_list_branches_of_git_repo() {
102-
List<String> branches = gitService.branches(node);
102+
List<String> branches = gitService.listBranches(node);
103103
Assert.assertNotNull(branches);
104104
Assert.assertEquals("develop", branches.get(0));
105105
Assert.assertEquals("master", branches.get(1));

0 commit comments

Comments
 (0)