Add Nostr event cache

This commit adds a simple in-memory Nostr Event cache, to reduce the
amount of bandwidth used as well as to improve performance.

Testing
-------

Setup:
  - Two iPhone simulators running Damus and on different accounts
  - Damus version: 774da239b92ed630fbf91fce42d9e233661c0d7f
  - Notepush: This commit
  - Push notifications turned on, setup to connect to localhost, and configured to receive DM notifications
  - Run Notepush with `RUST_LOG=DEBUG` env variable for debug logging
Steps:
1. Send a DM from one account to another.
  - Push notification should arrive with a few seconds delay
  - Push notification logs should mention that the event was cached
2. Send a DM again.
  - Push notification should arrive immediately
3. Wait for more than a minute
4. Send a DM again.
  - Push notification should take a few seconds again
  - Push notification logs should mention that the cache item expired and was deleted

Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
Closes: https://github.com/damus-io/notepush/issues/3
This commit is contained in:
Daniel D’Aquino
2024-08-05 18:01:52 -07:00
parent 388d49927b
commit 71258e3736
4 changed files with 177 additions and 13 deletions

View File

@ -1,5 +1,6 @@
pub mod nostr_network_helper;
mod nostr_event_extensions;
mod nostr_event_cache;
pub mod notification_manager;
pub use nostr_network_helper::NostrNetworkHelper;