mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-27 09:06:15 +01:00
fix: #13115, limit bodyLength length
send out notification if bodyLong.length exceeds limit add a max item limit to ttl cache get rid of has/get check if item isn't in cache get returns undefined
This commit is contained in:
@@ -22,6 +22,7 @@ const Notifications = module.exports;
|
|||||||
|
|
||||||
// ttlcache for email-only chat notifications
|
// ttlcache for email-only chat notifications
|
||||||
const notificationCache = ttlCache({
|
const notificationCache = ttlCache({
|
||||||
|
max: 1000,
|
||||||
ttl: (meta.config.notificationSendDelay || 60) * 1000,
|
ttl: (meta.config.notificationSendDelay || 60) * 1000,
|
||||||
noDisposeOnSet: true,
|
noDisposeOnSet: true,
|
||||||
dispose: sendEmail,
|
dispose: sendEmail,
|
||||||
@@ -246,11 +247,14 @@ async function pushToUids(uids, notification) {
|
|||||||
const delayNotificationTypes = ['new-chat', 'new-group-chat', 'new-public-chat'];
|
const delayNotificationTypes = ['new-chat', 'new-group-chat', 'new-public-chat'];
|
||||||
if (delayNotificationTypes.includes(notification.type)) {
|
if (delayNotificationTypes.includes(notification.type)) {
|
||||||
const cacheKey = `${notification.mergeId}|${results.uidsToEmail.join(',')}`;
|
const cacheKey = `${notification.mergeId}|${results.uidsToEmail.join(',')}`;
|
||||||
if (notificationCache.has(cacheKey)) {
|
|
||||||
const payload = notificationCache.get(cacheKey);
|
const payload = notificationCache.get(cacheKey);
|
||||||
|
if (payload !== undefined) {
|
||||||
notification.bodyLong = [payload.notification.bodyLong, notification.bodyLong].join('\n');
|
notification.bodyLong = [payload.notification.bodyLong, notification.bodyLong].join('\n');
|
||||||
}
|
}
|
||||||
notificationCache.set(cacheKey, { uids: results.uidsToEmail, notification });
|
notificationCache.set(cacheKey, { uids: results.uidsToEmail, notification });
|
||||||
|
if (notification.bodyLong.length >= 1000) {
|
||||||
|
notificationCache.delete(cacheKey);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
await sendEmail({ uids: results.uidsToEmail, notification });
|
await sendEmail({ uids: results.uidsToEmail, notification });
|
||||||
}
|
}
|
||||||
@@ -264,8 +268,7 @@ async function pushToUids(uids, notification) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function sendEmail({ uids, notification }, mergeId, reason) {
|
async function sendEmail({ uids, notification }, mergeId, reason) {
|
||||||
// Only act on cache item expiry
|
if (reason && reason === 'set') {
|
||||||
if (reason && reason !== 'stale') {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user