details: https://code.tryton.org/tryton/commit/8781e43917ad
branch: 7.8
user: Cédric Krier <[email protected]>
date: Fri Mar 20 18:41:23 2026 +0100
description:
Limit the size of the notification payload send to the bus
The payload size is limited by the database but also there is no point
to
overflow the user with too much notification popup.
So we publish only the first 4 messages and shorten them to 100 chars
per line.
Closes #14698
(grafted from cf3d190fe89d066a8720cc3c15655faa912526e5)
diffstat:
trytond/trytond/res/notification.py | 8 ++++++--
1 files changed, 6 insertions(+), 2 deletions(-)
diffs (28 lines):
diff -r 79dd5c8202a9 -r 8781e43917ad trytond/trytond/res/notification.py
--- a/trytond/trytond/res/notification.py Sat Mar 21 09:21:43 2026 +0100
+++ b/trytond/trytond/res/notification.py Fri Mar 20 18:41:23 2026 +0100
@@ -2,7 +2,9 @@
# this repository contains the full copyright notices and license terms.
import json
+import textwrap
from collections import defaultdict
+from functools import partial
from sql import Literal
from sql.aggregate import Count
@@ -95,10 +97,12 @@
where=((notification.user.in_(list(notifications_by_user)))
& notification.unread),
group_by=[notification.user]))
+ shorten = partial(textwrap.shorten, width=100, placeholder="...")
for user, count in cursor.fetchall():
+ user_notifications = notifications_by_user[user]
messages = [
- '\n'.join(filter(None, (n.label, n.description)))
- for n in notifications_by_user[user]]
+ '\n'.join(map(shorten, filter(None, (n.label, n.description))))
+ for n in user_notifications[:4]]
Bus.publish(
f'notification:{user}', {
'type': 'user-notification',