1
0
Fork 0
forked from fedi/mastodon

Perform processing that does not use the database before connecting to the database (#7168)

This commit is contained in:
abcang 2018-04-17 20:49:09 +09:00 committed by Eugen Rochko
parent 3c722fe687
commit 609bf93029

View file

@ -329,10 +329,8 @@ const startWorker = (workerId) => {
// Only messages that may require filtering are statuses, since notifications // Only messages that may require filtering are statuses, since notifications
// are already personalized and deletes do not matter // are already personalized and deletes do not matter
if (needsFiltering && event === 'update') { if (!needsFiltering || event !== 'update') {
pgPool.connect((err, client, done) => { transmit();
if (err) {
log.error(err);
return; return;
} }
@ -342,11 +340,21 @@ const startWorker = (workerId) => {
if (Array.isArray(req.filteredLanguages) && req.filteredLanguages.indexOf(unpackedPayload.language) !== -1) { if (Array.isArray(req.filteredLanguages) && req.filteredLanguages.indexOf(unpackedPayload.language) !== -1) {
log.silly(req.requestId, `Message ${unpackedPayload.id} filtered by language (${unpackedPayload.language})`); log.silly(req.requestId, `Message ${unpackedPayload.id} filtered by language (${unpackedPayload.language})`);
done();
return; return;
} }
if (req.accountId) { // When the account is not logged in, it is not necessary to confirm the block or mute
if (!req.accountId) {
transmit();
return;
}
pgPool.connect((err, client, done) => {
if (err) {
log.error(err);
return;
}
const queries = [ const queries = [
client.query(`SELECT 1 FROM blocks WHERE (account_id = $1 AND target_account_id IN (${placeholders(targetAccountIds, 2)})) OR (account_id = $2 AND target_account_id = $1) UNION SELECT 1 FROM mutes WHERE account_id = $1 AND target_account_id IN (${placeholders(targetAccountIds, 2)})`, [req.accountId, unpackedPayload.account.id].concat(targetAccountIds)), client.query(`SELECT 1 FROM blocks WHERE (account_id = $1 AND target_account_id IN (${placeholders(targetAccountIds, 2)})) OR (account_id = $2 AND target_account_id = $1) UNION SELECT 1 FROM mutes WHERE account_id = $1 AND target_account_id IN (${placeholders(targetAccountIds, 2)})`, [req.accountId, unpackedPayload.account.id].concat(targetAccountIds)),
]; ];
@ -367,14 +375,7 @@ const startWorker = (workerId) => {
done(); done();
log.error(err); log.error(err);
}); });
} else {
done();
transmit();
}
}); });
} else {
transmit();
}
}; };
subscribe(`${redisPrefix}${id}`, listener); subscribe(`${redisPrefix}${id}`, listener);