Skip to content

fix: notifications are deduped in memory, not just in persistant storage#211

Open
LeosPrograms wants to merge 1 commit into
main-0.7from
bugfix/notification-summary-reappearing
Open

fix: notifications are deduped in memory, not just in persistant storage#211
LeosPrograms wants to merge 1 commit into
main-0.7from
bugfix/notification-summary-reappearing

Conversation

@LeosPrograms
Copy link
Copy Markdown
Collaborator

No description provided.

Copy link
Copy Markdown
Member

@zippy zippy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some inline comments, and here are

Claude suggestions:

  1. O(n²) dedup with double-serialization per comparison. moss-store.ts:742-748: the filter + inner findIndex walks the feed twice per element, and getNotificationFeedEntryId calls encodeAndStringify (msgpack + base64) on each side of every comparison. And because the surrounding for (const notification of notifications) calls _notificationFeed.update once per notification, you compound this across the batch. A single-pass Map keeps the "newest wins" semantics and is O(n):
this._notificationFeed.update((feed) => {
  const newEntry: MossNotification = { source, notification, sourceName: options.sourceName };
  const seen = new Map<string, MossNotification>();
  seen.set(getNotificationFeedEntryId(newEntry), newEntry);
  for (const entry of feed) {
    const id = getNotificationFeedEntryId(entry);
    if (!seen.has(id)) seen.set(id, entry);
  }
  return [...seen.values()].sort((a, b) => b.notification.timestamp - a.notification.timestamp);
});
  1. Per-notification feed updates inside a batch loop. Since notifications can be an array, each one triggers its own _notificationFeed.update → re-sort → subscriber notification. For a batch of K notifications added against a feed of N entries, this is K separate sorts and K subscriber fan-outs. Could be hoisted to a single update that folds in all new entries at once. Not blocking, but cheap to fix while you're in there.

}
// 1. Persist if requested (tools do this, foyer doesn't)
if (options.persist && source.type === 'applet') {
const unreadNotifications = storeAppletNotifications(notifications, source.appletId, true, this.persistedStore);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This value is breaking CI because it's not read. and the value is pulled in the loop at line 722, should be re-using this value unless nothing was pulled by the guard here. Need to think this through better.

),
);

return deduplicatedFeed.sort(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inside loop this creates a n2 issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants