Skip to content

Conversation

jbsession
Copy link
Collaborator

@jbsession jbsession commented Aug 27, 2025

Relates to SES-4387

This PR reduces on-device storage by pruning orphaned recipient_settings rows and garbage-collecting avatar files cached under cache/remote_files. It builds a “keep set” of addresses still referenced by config and message history, then deletes everything else (DB rows and files).

What’s included

1.) Avatar cache tooling

  • RecipientAvatarDownloadManager: helper for the avatar cache directory and checking downloaded avatar files.
  • AvatarCacheCleaner (singleton): deletes unreferenced files from cache/remote_files.

2.) Address collectors

  • .allConfigAddresses() returns contacts, blinded contacts, communities, closed/legacy groups and closed-group members.
  • MmsSmsDatabase.getAllReferencedAddresses() - distinct addresses still present in the MMS/SMS union.
  • RecipientSettingsDatabase.getAllReferencedAvatarFiles() - profile-pic URLs/keys currently referenced by recipient settings.

3.) Pruning logic

  • Compute addressesToKeep = allConfigAddresses + getAllReferencedAddresses.
  • RecipientSettingsDatabase.cleanupRecipientSettings(addressesToKeep) removes rows not in addressesToKeep. Change notifications are emitted after the DB transaction.
  • Run AvatarCacheCleaner to remove orphaned avatar files that are not referenced by the keep set.

# Conflicts:
#	app/src/main/java/org/thoughtcrime/securesms/repository/ConversationRepository.kt
# Conflicts:
#	app/src/main/java/org/session/libsession/messaging/MessagingModuleConfiguration.kt
#	app/src/main/java/org/thoughtcrime/securesms/ApplicationContext.kt
#	app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationActivityV2.kt
#	app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationViewModel.kt
# Conflicts:
#	app/src/main/java/org/thoughtcrime/securesms/notifications/DefaultMessageNotifier.kt
#	app/src/main/java/org/thoughtcrime/securesms/repository/ConversationRepository.kt
@jbsession jbsession marked this pull request as ready for review August 27, 2025 06:44
Copy link
Collaborator

@SessionHero01 SessionHero01 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work!

@ThomasSession ThomasSession merged commit 675b179 into session-foundation:dev Aug 28, 2025
4 checks passed
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.

5 participants