Merge database writes for attachment compression.
This commit is contained in:
parent
f4bcfca323
commit
b4f2208bae
2 changed files with 20 additions and 15 deletions
|
@ -886,11 +886,13 @@ public class AttachmentTable extends DatabaseTable {
|
|||
*/
|
||||
public void updateAttachmentData(@NonNull DatabaseAttachment databaseAttachment,
|
||||
@NonNull MediaStream mediaStream,
|
||||
boolean onlyModifyThisAttachment)
|
||||
boolean onlyModifyThisAttachment,
|
||||
boolean withFastStart)
|
||||
throws MmsException, IOException
|
||||
{
|
||||
AttachmentId attachmentId = databaseAttachment.getAttachmentId();
|
||||
SQLiteDatabase database = databaseHelper.getSignalWritableDatabase();
|
||||
DataInfo oldDataInfo = getAttachmentDataFileInfo(databaseAttachment.getAttachmentId(), DATA);
|
||||
DataInfo oldDataInfo = getAttachmentDataFileInfo(attachmentId, DATA);
|
||||
|
||||
if (oldDataInfo == null) {
|
||||
throw new MmsException("No attachment data found!");
|
||||
|
@ -910,7 +912,15 @@ public class AttachmentTable extends DatabaseTable {
|
|||
|
||||
database.beginTransaction();
|
||||
try {
|
||||
dataInfo = deduplicateAttachment(dataInfo, databaseAttachment.getAttachmentId(), databaseAttachment.getTransformProperties());
|
||||
TransformProperties transformProperties = databaseAttachment.getTransformProperties();
|
||||
|
||||
dataInfo = deduplicateAttachment(dataInfo, attachmentId, transformProperties);
|
||||
|
||||
transformProperties = transformProperties.withSkipTransform();
|
||||
|
||||
if (withFastStart) {
|
||||
transformProperties = transformProperties.withMp4Faststart();
|
||||
}
|
||||
|
||||
ContentValues contentValues = new ContentValues();
|
||||
contentValues.put(SIZE, dataInfo.length);
|
||||
|
@ -920,9 +930,10 @@ public class AttachmentTable extends DatabaseTable {
|
|||
contentValues.put(DATA, dataInfo.file.getAbsolutePath());
|
||||
contentValues.put(DATA_RANDOM, dataInfo.random);
|
||||
contentValues.put(DATA_HASH, dataInfo.hash);
|
||||
contentValues.put(TRANSFORM_PROPERTIES, transformProperties.serialize());
|
||||
|
||||
int updateCount = updateAttachmentAndMatchingHashes(database,
|
||||
databaseAttachment.getAttachmentId(),
|
||||
attachmentId,
|
||||
isSingleUseOfData ? dataInfo.hash : oldDataInfo.hash,
|
||||
contentValues);
|
||||
|
||||
|
|
|
@ -7,7 +7,6 @@ import android.net.Uri;
|
|||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.WorkerThread;
|
||||
|
||||
import androidx.media3.common.MimeTypes;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
|
@ -23,8 +22,8 @@ import org.thoughtcrime.securesms.crypto.ModernEncryptingPartOutputStream;
|
|||
import org.thoughtcrime.securesms.database.AttachmentTable;
|
||||
import org.thoughtcrime.securesms.database.SignalDatabase;
|
||||
import org.thoughtcrime.securesms.events.PartProgressEvent;
|
||||
import org.thoughtcrime.securesms.jobmanager.JsonJobData;
|
||||
import org.thoughtcrime.securesms.jobmanager.Job;
|
||||
import org.thoughtcrime.securesms.jobmanager.JsonJobData;
|
||||
import org.thoughtcrime.securesms.jobmanager.impl.NetworkConstraint;
|
||||
import org.thoughtcrime.securesms.mms.DecryptableStreamUriLoader;
|
||||
import org.thoughtcrime.securesms.mms.MediaConstraints;
|
||||
|
@ -37,7 +36,6 @@ import org.thoughtcrime.securesms.util.BitmapDecodingException;
|
|||
import org.thoughtcrime.securesms.util.FeatureFlags;
|
||||
import org.thoughtcrime.securesms.util.ImageCompressionUtil;
|
||||
import org.thoughtcrime.securesms.util.MediaUtil;
|
||||
import org.thoughtcrime.securesms.util.MemoryFileDescriptor;
|
||||
import org.thoughtcrime.securesms.util.MemoryFileDescriptor.MemoryFileException;
|
||||
import org.thoughtcrime.securesms.video.InMemoryTranscoder;
|
||||
import org.thoughtcrime.securesms.video.StreamingTranscoder;
|
||||
|
@ -172,9 +170,8 @@ public final class AttachmentCompressionJob extends BaseJob {
|
|||
} else if (constraints.canResize(attachment)) {
|
||||
Log.i(TAG, "Compressing image.");
|
||||
try (MediaStream converted = compressImage(context, attachment, constraints)) {
|
||||
attachmentDatabase.updateAttachmentData(attachment, converted, false);
|
||||
attachmentDatabase.updateAttachmentData(attachment, converted, false, false);
|
||||
}
|
||||
attachmentDatabase.markAttachmentAsTransformed(attachmentId, false);
|
||||
} else if (constraints.isSatisfied(context, attachment)) {
|
||||
Log.i(TAG, "Not compressing.");
|
||||
attachmentDatabase.markAttachmentAsTransformed(attachmentId, false);
|
||||
|
@ -250,7 +247,7 @@ public final class AttachmentCompressionJob extends BaseJob {
|
|||
100));
|
||||
|
||||
try (MediaStream mediaStream = new MediaStream(ModernDecryptingPartInputStream.createFor(attachmentSecret, file, 0), MimeTypes.VIDEO_MP4, 0, 0)) {
|
||||
attachmentDatabase.updateAttachmentData(attachment, mediaStream, true);
|
||||
attachmentDatabase.updateAttachmentData(attachment, mediaStream, true, false);
|
||||
}
|
||||
} finally {
|
||||
if (!file.delete()) {
|
||||
|
@ -258,8 +255,6 @@ public final class AttachmentCompressionJob extends BaseJob {
|
|||
}
|
||||
}
|
||||
|
||||
attachmentDatabase.markAttachmentAsTransformed(attachment.getAttachmentId(), false);
|
||||
|
||||
return Objects.requireNonNull(attachmentDatabase.getAttachment(attachment.getAttachmentId()));
|
||||
} else {
|
||||
Log.i(TAG, "Transcode was not required");
|
||||
|
@ -278,8 +273,7 @@ public final class AttachmentCompressionJob extends BaseJob {
|
|||
100,
|
||||
percent));
|
||||
}, cancelationSignal)) {
|
||||
attachmentDatabase.updateAttachmentData(attachment, mediaStream, true);
|
||||
attachmentDatabase.markAttachmentAsTransformed(attachment.getAttachmentId(), mediaStream.getFaststart());
|
||||
attachmentDatabase.updateAttachmentData(attachment, mediaStream, true, mediaStream.getFaststart());
|
||||
}
|
||||
|
||||
eventBus.postSticky(new PartProgressEvent(attachment,
|
||||
|
|
Loading…
Add table
Reference in a new issue