electron-push-receiver icon indicating copy to clipboard operation
electron-push-receiver copied to clipboard

persistentIds grows without bound?

Open RandomEngy opened this issue 2 years ago • 2 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?

RandomEngy avatar Jan 09 '23 05:01 RandomEngy

I added it in my code to solve it:

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

but Its odd

natopedroso avatar Apr 11 '23 12:04 natopedroso

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.

RandomEngy avatar Apr 11 '23 14:04 RandomEngy