Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Ignore artifacts:
build
coverage
9 changes: 9 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"semi": true,
"singleQuote": true,
"trailingComma": "es5",
"useTabs": true,
"tabWidth": 2,
"arrowParens": "avoid",
"printWidth": 80
}
1 change: 1 addition & 0 deletions install/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@
"postcss": "8.4.38",
"postcss-clean": "1.2.0",
"progress-webpack-plugin": "1.0.16",
"prettier": "3.3.3",
"prompt": "1.3.0",
"ioredis": "5.4.1",
"rimraf": "5.0.7",
Expand Down
15 changes: 10 additions & 5 deletions src/posts/category.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@

'use strict';


const _ = require('lodash');

const db = require('../database');
Expand All @@ -18,7 +16,9 @@ module.exports = function (Posts) {
const tids = _.uniq(postData.map(post => post && post.tid).filter(Boolean));
const topicData = await topics.getTopicsFields(tids, ['cid']);
const tidToTopic = _.zipObject(tids, topicData);
const cids = postData.map(post => tidToTopic[post.tid] && tidToTopic[post.tid].cid);
const cids = postData.map(
post => tidToTopic[post.tid] && tidToTopic[post.tid].cid
);
return cids;
};

Expand All @@ -30,12 +30,17 @@ module.exports = function (Posts) {
if (!Array.isArray(cid) || cid.length === 1) {
return await filterPidsBySingleCid(pids, cid);
}
const pidsArr = await Promise.all(cid.map(c => Posts.filterPidsByCid(pids, c)));
const pidsArr = await Promise.all(
cid.map(c => Posts.filterPidsByCid(pids, c))
);
return _.union(...pidsArr);
};

async function filterPidsBySingleCid(pids, cid) {
const isMembers = await db.isSortedSetMembers(`cid:${parseInt(cid, 10)}:pids`, pids);
const isMembers = await db.isSortedSetMembers(
`cid:${parseInt(cid, 10)}:pids`,
pids
);
return pids.filter((pid, index) => pid && isMembers[index]);
}
};