Skip to content

Commit 7318b45

Browse files
committed
fix #760
1 parent 4cafef1 commit 7318b45

File tree

3 files changed

+59
-20
lines changed

3 files changed

+59
-20
lines changed

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,19 @@
77
[![捐赠][badge:donate-zh]][shuzijun-donate]
88
[![内推][badge:referrals]][shuzijun-referrals]
99

10+
## 8.16.0
11+
12+
### Added
13+
14+
### Changed
15+
16+
### Deprecated
17+
18+
### Fixed
19+
- fix [#760](https://github.com/shuzijun/leetcode-editor/issues/760)
20+
### Removed
21+
22+
1023
## 8.15.0
1124

1225
### Added

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
pluginGroup = com.shuzijun.leetcode
22
pluginName = leetcode-editor
3-
pluginVersion = 8.15
3+
pluginVersion = 8.16
44

55
pluginSinceBuild = 223.0
66
pluginUntilBuild =

src/main/java/com/shuzijun/leetcode/plugin/manager/ArticleManager.java

Lines changed: 45 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import java.io.File;
1616
import java.util.ArrayList;
1717
import java.util.List;
18+
import java.util.concurrent.*;
1819

1920
/**
2021
* @author shuzijun
@@ -80,33 +81,58 @@ public static String formatMarkdown(String content, String host) {
8081

8182
public static List<Solution> getSolutionList(String titleSlug, Project project) {
8283
List<Solution> solutionList = new ArrayList<>();
83-
84+
ExecutorService executorService = Executors.newFixedThreadPool(4);
8485
try {
85-
HttpResponse response = Graphql.builder().cn(URLUtils.isCn()).operationName("questionSolutionArticles").
86-
variables("questionSlug", titleSlug).variables("first", 200).variables("skip", 0).variables("orderBy", "DEFAULT").request();
87-
if (response.getStatusCode() == 200) {
88-
JSONArray edges = JSONObject.parseObject(response.getBody()).getJSONObject("data").getJSONObject("questionSolutionArticles").getJSONArray("edges");
89-
for (int i = 0; i < edges.size(); i++) {
90-
JSONObject node = edges.getJSONObject(i).getJSONObject("node");
91-
Solution solution = new Solution();
92-
solution.setTitle(node.getString("title"));
93-
solution.setSlug(node.getString("slug"));
94-
solution.setSummary(node.getString("summary"));
86+
int pageCount = 4;
87+
CountDownLatch latch = new CountDownLatch(pageCount);
88+
List<Solution>[] results = new List[pageCount];
9589

96-
StringBuilder tagsSb = new StringBuilder();
97-
JSONArray tags = node.getJSONArray("tags");
98-
for (int j = 0; j < tags.size(); j++) {
99-
tagsSb.append("[").append(tags.getJSONObject(j).getString("name")).append("] ");
90+
for (int i = 0; i < pageCount; i++) {
91+
int pageIndex = i;
92+
int skip = pageIndex * 30;
93+
executorService.submit(() -> {
94+
try {
95+
List<Solution> solutions = new ArrayList<>();
96+
HttpResponse response = Graphql.builder().cn(URLUtils.isCn()).operationName("questionSolutionArticles").
97+
variables("questionSlug", titleSlug).variables("first", 30).variables("skip", skip).variables("orderBy", "DEFAULT").request();
98+
if (response.getStatusCode() == 200) {
99+
JSONArray edges = JSONObject.parseObject(response.getBody()).getJSONObject("data").getJSONObject("questionSolutionArticles").getJSONArray("edges");
100+
for (int j = 0; j < edges.size(); j++) {
101+
JSONObject node = edges.getJSONObject(j).getJSONObject("node");
102+
Solution solution = new Solution();
103+
solution.setTitle(node.getString("title"));
104+
solution.setSlug(node.getString("slug"));
105+
solution.setSummary(node.getString("summary"));
106+
107+
StringBuilder tagsSb = new StringBuilder();
108+
JSONArray tags = node.getJSONArray("tags");
109+
for (int k = 0; k < tags.size(); k++) {
110+
tagsSb.append("[").append(tags.getJSONObject(k).getString("name")).append("] ");
111+
}
112+
solution.setTags(tagsSb.toString());
113+
solutions.add(solution);
114+
}
115+
results[pageIndex] = solutions;
116+
} else {
117+
MessageUtils.getInstance(project).showWarnMsg("error", PropertiesUtils.getInfo("response.code"));
118+
}
119+
} finally {
120+
latch.countDown();
100121
}
101-
solution.setTags(tagsSb.toString());
102-
solutionList.add(solution);
122+
});
123+
}
124+
125+
latch.await();
126+
for (List<Solution> pageResult : results) {
127+
if (pageResult != null) {
128+
solutionList.addAll(pageResult);
103129
}
104-
} else {
105-
MessageUtils.getInstance(project).showWarnMsg("error", PropertiesUtils.getInfo("response.code"));
106130
}
107131
} catch (Exception e) {
108132
LogUtils.LOG.error("solutionList acquisition failed", e);
109133
MessageUtils.getInstance(project).showWarnMsg("error", PropertiesUtils.getInfo("response.code"));
134+
} finally {
135+
executorService.shutdown();
110136
}
111137
return solutionList;
112138

0 commit comments

Comments
 (0)