mirror of
https://github.com/signalapp/Signal-Android.git
synced 2025-12-20 02:58:45 +00:00
Optimize more during low disk situations.
This commit is contained in:
committed by
jeffrey-signal
parent
8eef29cd77
commit
872c7c5ce2
@@ -1112,7 +1112,7 @@ class AttachmentTable(
|
||||
* Marking offloaded only clears the strong references to the on disk file and clears other local file data like hashes.
|
||||
* Another operation must run to actually delete the data from disk. See [deleteAbandonedAttachmentFiles].
|
||||
*/
|
||||
fun markEligibleAttachmentsAsOptimized() {
|
||||
fun markEligibleAttachmentsAsOptimized(minimumAge: Duration = 30.days) {
|
||||
val now = System.currentTimeMillis()
|
||||
|
||||
val subSelect = """
|
||||
@@ -1136,7 +1136,7 @@ class AttachmentTable(
|
||||
)
|
||||
AND
|
||||
(
|
||||
${MessageTable.TABLE_NAME}.${MessageTable.DATE_RECEIVED} < ${now - 30.days.inWholeMilliseconds}
|
||||
${MessageTable.TABLE_NAME}.${MessageTable.DATE_RECEIVED} < ${now - minimumAge.inWholeMilliseconds}
|
||||
)
|
||||
"""
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
package org.thoughtcrime.securesms.jobs
|
||||
|
||||
import org.signal.core.util.DiskUtil
|
||||
import org.signal.core.util.logging.Log
|
||||
import org.thoughtcrime.securesms.database.SignalDatabase
|
||||
import org.thoughtcrime.securesms.dependencies.AppDependencies
|
||||
@@ -51,7 +52,16 @@ class OptimizeMediaJob private constructor(parameters: Parameters) : Job(paramet
|
||||
RestoreAttachmentJob.Queues.OFFLOAD_RESTORE.forEach { queue -> AppDependencies.jobManager.add(CheckRestoreMediaLeftJob(queue)) }
|
||||
|
||||
Log.i(TAG, "Optimizing media in the db")
|
||||
SignalDatabase.attachments.markEligibleAttachmentsAsOptimized()
|
||||
|
||||
val available = DiskUtil.getAvailableSpace(context).bytes.toFloat()
|
||||
val total = DiskUtil.getTotalDiskSize(context).bytes.toFloat()
|
||||
val remaining = (total - available) / total * 100
|
||||
|
||||
val minimumAge = if (remaining > 5f) 30.days else 15.days
|
||||
|
||||
Log.i(TAG, "${"%.1f".format(remaining)}% storage available, not optimizing the last $minimumAge of attachments")
|
||||
|
||||
SignalDatabase.attachments.markEligibleAttachmentsAsOptimized(minimumAge)
|
||||
|
||||
Log.i(TAG, "Deleting abandoned attachment files")
|
||||
val count = SignalDatabase.attachments.deleteAbandonedAttachmentFiles()
|
||||
|
||||
Reference in New Issue
Block a user