mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-22 09:49:30 +01:00
Perform individual decryptions inside a database transaction.
Required a lot of random locking work to prevent deadlocking, but overall this results in about a 2x speed increase for decryptions.
This commit is contained in:
committed by
Cody Henthorne
parent
d56607a686
commit
28f3ded4bd
@@ -0,0 +1,32 @@
|
||||
package org.thoughtcrime.securesms.database;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import net.sqlcipher.database.SQLiteDatabase;
|
||||
|
||||
import java.io.Closeable;
|
||||
|
||||
public final class DatabaseLock {
|
||||
|
||||
public static @NonNull Lock acquire(@NonNull Context context) {
|
||||
SQLiteDatabase db = DatabaseFactory.getInstance(context).getRawDatabase();
|
||||
|
||||
if (db.isDbLockedByCurrentThread()) {
|
||||
return () -> {};
|
||||
}
|
||||
|
||||
db.beginTransaction();
|
||||
|
||||
return () -> {
|
||||
db.setTransactionSuccessful();
|
||||
db.endTransaction();
|
||||
};
|
||||
}
|
||||
|
||||
public interface Lock extends Closeable {
|
||||
@Override
|
||||
void close();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user