This commit reworks the cache data structures and operations to
significantly cut down on unnecessary allocations and improve overall
cache management logic.
Key changes include:
- Replacing event-specific CacheEntry types with a generic CacheEntry<T>
that stores values and timestamps.
- Removing the old Arc references in HashMap entries, reducing
reference-counted pointer overhead.
- Providing helper methods (new(), maybe(), empty(), value()) on
CacheEntry for more ergonomic and explicit value handling.
- Simplifying the retrieval functions (get_mute_list, get_relay_list,
get_contact_list) by using a shared helper (get_cache_entry) that
checks for expiration and removes stale entries automatically.
- Streamlining add_event and related cache insertion methods to insert
the correct CacheEntry variant depending on the event kind.
- Removing unnecessary methods (e.g., references_pubkey) and simplifying
extensions in nostr_event_extensions.rs.
- Enhancing code clarity by separating expiration logic from retrieval
and insertion, making the cache easier to maintain, debug, and extend.
These improvements should reduce runtime memory overhead and increase
code clarity, while maintaining the existing external behavior of the
cache. Future changes will be easier to implement, as the new generic
CacheEntry abstraction and simplified code paths provide a more
maintainable foundation.
Signed-off-by: William Casarin <jb55@jb55.com>
This commit improves the robustness of mute list handling:
1. It listens to new mute lists from the relay interface, and saves them whenever there is a new one
2. It uses the user's own relay lists to fetch events (such as mute lists), helping to ensure we get their mute lists even when they are not stored in the Damus relay
3. It saves events it sees when fetching them from the network, if applicable
Changelog-Changed: Improved robustness of mute handling
Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
There was an issue where an empty cache entry would get interpreted as a
"no cache entry found" situation and cause notepush to always fetch a
new mutelist
Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
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