MatthieuLemoine / electron-push-receiver

A module to bring Web Push support to Electron allowing it to receive notifications from Firebase Cloud Messaging (FCM).

Home Page:https://medium.com/@MatthieuLemoine/my-journey-to-bring-web-push-support-to-node-and-electron-ce70eea1c0b0

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

persistentIds grows without bound?

RandomEngy opened this issue · comments

Looking at this code: https://github.com/MatthieuLemoine/electron-push-receiver/blob/master/src/index.js

It looks like persistentIds just grows with each push notification received. And each time you get a message, it's parsing out the whole list from config, creating a new array with an additional element, then re-saving it back to config. That seems like after a lot of notifications could get very slow.

Do we really need to keep every single one around?

This code in push-receiver seems to be resetting its local copy of persistentIds on a login event, and it's trying to log in every time we connect. Perhaps the right thing would be clear the persistentIds from config after a successful listen() call?

I added it in my code to solve it:

  config.persistentIds = config?.persistentIds.slice(
    config?.persistentIds?.length - 10,
    config?.persistentIds?.length,
  );

but Its odd

I've written a variant of this in Rust and I've implemented it this way:

The core library allows you to give it a list of persistent IDs to ignore on connect, but it does not store its own local copy of them.

The calling code adds the persistent IDs to a SQLite table as the messages come in. On connect, it supplies the persistent IDs and clears the SQLite table on a successful connect.