From f8c8038a068c8d14c6736ba435130f1f4167a4aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Fri, 4 Oct 2019 19:19:01 -0400 Subject: [PATCH] refactor: remove log, topics.exists --- src/topics/tools.js | 18 +++++++++--------- src/user/auth.js | 6 ++---- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/topics/tools.js b/src/topics/tools.js index 84c6a1032e..7b3fbe977e 100644 --- a/src/topics/tools.js +++ b/src/topics/tools.js @@ -22,15 +22,15 @@ module.exports = function (Topics) { }; async function toggleDelete(tid, uid, isDelete) { - const exists = await Topics.exists(tid); - if (!exists) { + const topicData = await Topics.getTopicData(tid); + if (!topicData) { throw new Error('[[error:no-topic]]'); } const canDelete = await privileges.topics.canDelete(tid, uid); if (!canDelete) { throw new Error('[[error:no-privileges]]'); } - const topicData = await Topics.getTopicFields(tid, ['tid', 'cid', 'uid', 'deleted', 'title', 'mainPid']); + if (topicData.deleted && isDelete) { throw new Error('[[error:topic-already-deleted]]'); } else if (!topicData.deleted && !isDelete) { @@ -61,17 +61,17 @@ module.exports = function (Topics) { } topicTools.purge = async function (tid, uid) { - const exists = await Topics.exists(tid); - if (!exists) { + const topicData = await Topics.getTopicData(tid); + if (!topicData) { return; } const canPurge = await privileges.topics.canPurge(tid, uid); if (!canPurge) { throw new Error('[[error:no-privileges]]'); } - const cid = await Topics.getTopicField(tid, 'cid'); + await Topics.purgePostsAndTopic(tid, uid); - return { tid: tid, cid: cid, uid: uid }; + return { tid: tid, cid: topicData.cid, uid: uid }; }; topicTools.lock = async function (tid, uid) { @@ -148,7 +148,7 @@ module.exports = function (Topics) { const tids = data.map(topic => topic && topic.tid); const topicData = await Topics.getTopicsFields(tids, ['cid']); - var uniqueCids = _.uniq(topicData.map(topicData => topicData && topicData.cid)); + const uniqueCids = _.uniq(topicData.map(topicData => topicData && topicData.cid)); if (uniqueCids.length > 1 || !uniqueCids.length || !uniqueCids[0]) { throw new Error('[[error:invalid-data]]'); } @@ -214,7 +214,7 @@ module.exports = function (Topics) { oldCid: oldCid, }), ]); - var hookData = _.clone(data); + const hookData = _.clone(data); hookData.fromCid = oldCid; hookData.toCid = cid; hookData.tid = tid; diff --git a/src/user/auth.js b/src/user/auth.js index 5cbd1a2edd..a9874ab79c 100644 --- a/src/user/auth.js +++ b/src/user/auth.js @@ -134,12 +134,10 @@ module.exports = function (User) { const sessionUUIDKeys = uids.map(uid => 'uid:' + uid + ':sessionUUID:sessionId'); const sids = _.flatten(await db.getSortedSetRange(sessionKeys, 0, -1)); - const promises = [ + await Promise.all([ db.deleteAll(sessionKeys.concat(sessionUUIDKeys)), ...sids.map(sid => sessionStoreDestroy(sid)), - ]; - console.log('epic', promises); - await Promise.all(promises); + ]); }, { batch: 1000 }); }; };