@waline/vercel 1.15.0 → 1.15.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@waline/vercel",
3
- "version": "1.15.0",
3
+ "version": "1.15.3",
4
4
  "description": "vercel server for waline comment system",
5
5
  "keywords": [
6
6
  "waline",
@@ -106,9 +106,10 @@ module.exports = {
106
106
  disallowIPList: [],
107
107
  secureDomains: SECURE_DOMAINS ? SECURE_DOMAINS.split(/\s*,\s*/) : undefined,
108
108
  disableUserAgent: DISABLE_USERAGENT && !isFalse(DISABLE_USERAGENT),
109
- levels: isFalse(LEVELS)
110
- ? false
111
- : LEVELS.split(/\s*,\s*/).map((v) => Number(v)),
109
+ levels:
110
+ !LEVELS || isFalse(LEVELS)
111
+ ? false
112
+ : LEVELS.split(/\s*,\s*/).map((v) => Number(v)),
112
113
  avatarProxy,
113
114
  oauthUrl,
114
115
  markdown,
@@ -264,6 +264,13 @@ module.exports = class extends BaseRest {
264
264
  ...comments.filter(({ rid, sticky }) => !rid && sticky),
265
265
  ...comments.filter(({ rid, sticky }) => !rid && !sticky),
266
266
  ].slice(pageOffset, pageOffset + pageSize);
267
+ const rootIds = {};
268
+ rootComments.forEach(({ objectId }) => {
269
+ rootIds[objectId] = true;
270
+ });
271
+ comments = comments.filter(
272
+ (cmt) => rootIds[cmt.objectId] || rootIds[cmt.rid]
273
+ );
267
274
  } else {
268
275
  rootComments = await this.modelInstance.select(
269
276
  { ...where, rid: undefined },
@@ -18,4 +18,32 @@ module.exports = {
18
18
 
19
19
  return -1;
20
20
  },
21
+ promiseAllQueue(promises, taskNum) {
22
+ return new Promise((resolve, reject) => {
23
+ const ret = [];
24
+ let index = 0;
25
+ let count = 0;
26
+
27
+ function runTask() {
28
+ const idx = index;
29
+ index += 1;
30
+ if (index > promises.length) {
31
+ return Promise.resolve();
32
+ }
33
+
34
+ return promises[idx].then((data) => {
35
+ ret[idx] = data;
36
+ count += 1;
37
+ if (count === promises.length) {
38
+ resolve(ret);
39
+ }
40
+ return runTask();
41
+ }, reject);
42
+ }
43
+
44
+ for (let i = 0; i < taskNum; i++) {
45
+ runTask();
46
+ }
47
+ });
48
+ },
21
49
  };
@@ -139,6 +139,7 @@ module.exports = class extends Base {
139
139
 
140
140
  // todo: query optimize
141
141
  const counts = [];
142
+ const countsPromise = [];
142
143
  for (let i = 0; i < options.group.length; i++) {
143
144
  const groupName = options.group[i];
144
145
  if (!where._complex || !Array.isArray(where._complex[groupName])) {
@@ -157,17 +158,21 @@ module.exports = class extends Base {
157
158
  _complex: undefined,
158
159
  [groupName]: where._complex[groupName][1][j],
159
160
  };
160
- const num = await this.count(groupWhere, {
161
+ const countPromise = this.count(groupWhere, {
161
162
  ...options,
162
163
  group: undefined,
164
+ }).then((num) => {
165
+ counts.push({
166
+ ...groupFlatValue,
167
+ [groupName]: where._complex[groupName][1][j],
168
+ count: num,
169
+ });
163
170
  });
164
- counts.push({
165
- ...groupFlatValue,
166
- [groupName]: where._complex[groupName][1][j],
167
- count: num,
168
- });
171
+ countsPromise.push(countPromise);
169
172
  }
170
173
  }
174
+
175
+ await think.promiseAllQueue(countsPromise, 3);
171
176
  return counts;
172
177
  }
173
178