Async refactor in place (#7736)

* feat: allow both callback&and await

* feat: ignore async key

* feat: callbackify and promisify in same file

* Revert "feat: callbackify and promisify in same file"

This reverts commit cea206a9b8.

* feat: no need to store .callbackify

* feat: change getTopics to async

* feat: remove .async

* fix: byScore

* feat: rewrite topics/index and social with async/await

* fix: rewrite topics/data.js

fix issue with async.waterfall, only pass result if its not undefined

* feat: add callbackify to redis/psql

* feat: psql use await

* fix: redis 🌋

* feat: less returns

* feat: more await rewrite

* fix: redis tests

* feat: convert sortedSetAdd

rewrite psql transaction to async/await

* feat: 🐶

* feat: test

* feat: log client and query

* feat: log bind

* feat: more logs

* feat: more logs

* feat: check perform

* feat: dont callbackify transaction

* feat: remove logs

* fix: main functions

* feat: more logs

* fix: increment

* fix: rename

* feat: remove cls

* fix: remove console.log

* feat: add deprecation message to .async usage

* feat: update more dbal methods

* fix: redis :voodoo:

* feat:  fix redis zrem, convert setObject

* feat: upgrade getObject methods

* fix: psql getObjectField

* fix: redis tests

* feat: getObjectKeys

* feat: getObjectValues

* feat: isObjectField

* fix: add missing return

* feat: delObjectField

* feat: incrObjectField

* fix: add missing await

* feat: remove exposed helpers

* feat: list methods

* feat: flush/empty

* feat: delete

* fix: redis delete all

* feat: get/set

* feat: incr/rename

* feat: type

* feat: expire

* feat: setAdd

* feat: setRemove

* feat: isSetMember

* feat: getSetMembers

* feat: setCount, setRemoveRandom

* feat: zcard,zcount

* feat: sortedSetRank

* feat: isSortedSetMember

* feat: zincrby

* feat: sortedSetLex

* feat: processSortedSet

* fix: add mising await

* feat: debug psql

* fix: psql test

* fix: test

* fix: another test

* fix: test fix

* fix: psql tests

* feat: remove logs

* feat: user arrow func

use builtin async promises

* feat: topic bookmarks

* feat: topic.delete

* feat: topic.restore

* feat: topics.purge

* feat: merge

* feat: suggested

* feat: topics/user.js

* feat: topics modules

* feat: topics/follow

* fix: deprecation msg

* feat: fork

* feat: topics/posts

* feat: sorted/recent

* feat: topic/teaser

* feat: topics/tools

* feat: topics/unread

* feat: add back node versions

disable deprecation notice
wrap async controllers in try/catch

* feat: use db directly

* feat: promisify in place

* fix: redis/psql

* feat: deprecation message

logs for psql

* feat: more logs

* feat: more logs

* feat: logs again

* feat: more logs

* fix: call release

* feat: restore travis, remove logs

* fix: loops

* feat: remove .async. usage
This commit is contained in:
Barış Soner Uşaklı
2019-07-09 12:46:49 -04:00
committed by GitHub
parent 43ce5f8af3
commit 805dcd7ca2
73 changed files with 4030 additions and 6110 deletions

View File

@@ -1,6 +1,5 @@
'use strict';
var async = require('async');
var plugins = require('./plugins');
var db = require('./database');
@@ -8,9 +7,9 @@ var social = module.exports;
social.postSharing = null;
social.getPostSharing = function (callback) {
social.getPostSharing = async function () {
if (social.postSharing) {
return setImmediate(callback, null, social.postSharing);
return social.postSharing;
}
var networks = [
@@ -25,51 +24,28 @@ social.getPostSharing = function (callback) {
class: 'fa-twitter',
},
];
networks = await plugins.fireHook('filter:social.posts', networks);
const activated = await db.getSetMembers('social:posts.activated');
networks.forEach(function (network) {
network.activated = activated.includes(network.id);
});
async.waterfall([
function (next) {
plugins.fireHook('filter:social.posts', networks, next);
},
function (networks, next) {
db.getSetMembers('social:posts.activated', next);
},
function (activated, next) {
networks.forEach(function (network) {
network.activated = activated.includes(network.id);
});
social.postSharing = networks;
next(null, networks);
},
], callback);
social.postSharing = networks;
return networks;
};
social.getActivePostSharing = function (callback) {
async.waterfall([
function (next) {
social.getPostSharing(next);
},
function (networks, next) {
networks = networks.filter(network => network && network.activated);
next(null, networks);
},
], callback);
social.getActivePostSharing = async function () {
const networks = await social.getPostSharing();
return networks.filter(network => network && network.activated);
};
social.setActivePostSharingNetworks = function (networkIDs, callback) {
async.waterfall([
function (next) {
db.delete('social:posts.activated', next);
},
function (next) {
if (!networkIDs.length) {
return next();
}
db.setAdd('social:posts.activated', networkIDs, next);
},
function (next) {
social.postSharing = null;
next();
},
], callback);
social.setActivePostSharingNetworks = async function (networkIDs) {
await db.delete('social:posts.activated');
if (!networkIDs.length) {
return;
}
await db.setAdd('social:posts.activated', networkIDs);
social.postSharing = null;
};
require('./promisify')(social);