Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

reply cache to delete our DM if they delete #18

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

fasiha
Copy link
Collaborator

@fasiha fasiha commented Sep 15, 2023

Previously, if we received a notification that someone deleted a toot, we asked our server for our most recent sent toots to see if we could find a reply to the deleted toot. If we found such a reply, we'd delete it (so it's not cluttering the other user's DMs).

Most of the time this does nothing because

  1. the vast majority of deletes are of messages that we haven't responded to (i.e., either with no images or with captions).
  2. But also because we can only ask the server for our most recent messages and we might have sent a reply to the now-deleted a while ago.

Instead of burdening the server to do this unlikely-to-be-useful search, this PR proposes an alternative: we store in memory a cache mapping other people's message IDs to our replies. When we DM someone about missing captions, it creates an entry in the cache. If we get a delete, we check the cache for the deleted message ID and if we find a hit, we delete our message and delete the entry from the cache.

We don't want the cache to grow infinitely so we cap it at some reasonable value (10'000 entries in this PR), and every 12 hours we run a cleanup operation to bring it to that size if it's grown beyond it.

Upsides:

  • we don't burden the server
  • we will likely detect and delete even months-old replies
    • (assuming the server stays running that long)

Downsides:

  • the cache is in-memory and not persisted to disk. We lose the cache every time the server reboots (which is every few days recently, since I'm adding features).
    • we could save the cache to disk every few hours and on server shutdown but I don't want to have a random list of people's message IDs (that botsin.space has assigned) on the Glitch server, seems like a privacy 馃あ

Bonus:

  • we now also listen to edit messages and delete our DM if someone edits their toot and adds captions!

Potential enhancements:

  • later once we detect missing captions in people's boosts, we should detect if someone has unboosted and delete our DM to them too
  • TODO now: delete from our cache when someone favorites our DM

(My overall goal to reduce server load is so we can turn on boost analysis 馃槆)

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.

None yet

1 participant