java-topology/defects/mattermost/patch/mattermost-0001-notification-push-map.patch
russell@unturf.com c9e86c450c opensmtpd-0001: mta_handle_envelope TAILQ_FOREACH O(N²) task lookup — patch + unit test
Add patch replacing linear TAILQ_FOREACH scan in mta_handle_envelope()
with tree_get() on a per-relay task_by_msgid splay-tree index; assign
UNDF-2026-000000201. Unit test confirms 100x op-count improvement at
N=100 tasks/relay.
2026-03-30 07:00:50 -04:00

37 lines
1.8 KiB
Diff
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# UNDF: UNDF-2026-000000162
--- a/server/channels/app/notification.go
+++ b/server/channels/app/notification.go
@@ -525,6 +525,14 @@ func (a *App) sendNotifications(rctx request.CTX, post *model.Post, team *model.
)
+ // CWE-407 fix: notificationsForCRT.Push is a model.StringArray ([]string).
+ // Calling .Contains(id) inside the loops below is O(P) per call where P is
+ // the length of the Push slice. With N users in mentionedUsersList and M
+ // users in allActivityPushUserIds the original code is O((N+M)×P).
+ // Build a map once for O(1) lookups, reducing the total to O(N+M+P).
+ crtPushSet := make(map[string]bool, len(notificationsForCRT.Push))
+ for _, crtID := range notificationsForCRT.Push {
+ crtPushSet[crtID] = true
+ }
+
for _, id := range mentionedUsersList {
if profileMap[id] == nil {
a.CountNotificationReason(model.NotificationStatusError, model.NotificationTypePush, model.NotificationReasonMissingProfile, model.NotificationNoPlatform)
@@ -541,7 +549,7 @@ func (a *App) sendNotifications(rctx request.CTX, post *model.Post, team *model.
continue
}
- if notificationsForCRT.Push.Contains(id) {
+ if crtPushSet[id] {
rctx.Logger().LogM(mlog.MlvlNotificationTrace, "Skipped direct push notification - will send as CRT notification",
mlog.String("type", model.NotificationTypePush),
mlog.String("post_id", post.Id),
@@ -593,7 +601,7 @@ func (a *App) sendNotifications(rctx request.CTX, post *model.Post, team *model.
continue
}
- if notificationsForCRT.Push.Contains(id) {
+ if crtPushSet[id] {
rctx.Logger().LogM(mlog.MlvlNotificationTrace, "Skipped direct push notification - will send as CRT notification",
mlog.String("type", model.NotificationTypePush),
mlog.String("post_id", post.Id),