details:   https://code.tryton.org/tryton/commit/cf3d190fe89d
branch:    default
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
diffstat:

 trytond/trytond/res/notification.py |  8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)

diffs (28 lines):

diff -r 3b490a8531a5 -r cf3d190fe89d trytond/trytond/res/notification.py
--- a/trytond/trytond/res/notification.py       Sat Mar 21 09:22:21 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.aggregate import Count
 
@@ -94,10 +96,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',

Reply via email to