mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-20 08:39:22 +01:00
Add measurements, improve MSL insert.
This commit is contained in:
@@ -231,30 +231,31 @@ class MessageSendLogDatabase constructor(context: Context?, databaseHelper: SQLC
|
||||
|
||||
val payloadId: Long = db.insert(PayloadTable.TABLE_NAME, null, payloadValues)
|
||||
|
||||
val recipientValues: MutableList<ContentValues> = mutableListOf()
|
||||
recipients.forEach { recipientDevice ->
|
||||
recipientDevice.devices.forEach { device ->
|
||||
val recipientValues = ContentValues().apply {
|
||||
recipientValues += ContentValues().apply {
|
||||
put(RecipientTable.PAYLOAD_ID, payloadId)
|
||||
put(RecipientTable.RECIPIENT_ID, recipientDevice.recipientId.serialize())
|
||||
put(RecipientTable.DEVICE, device)
|
||||
}
|
||||
|
||||
db.insert(RecipientTable.TABLE_NAME, null, recipientValues)
|
||||
}
|
||||
}
|
||||
SqlUtil.buildBulkInsert(RecipientTable.TABLE_NAME, arrayOf(RecipientTable.PAYLOAD_ID, RecipientTable.RECIPIENT_ID, RecipientTable.DEVICE), recipientValues)
|
||||
.forEach { query -> db.execSQL(query.where, query.whereArgs) }
|
||||
|
||||
val messageValues: MutableList<ContentValues> = mutableListOf()
|
||||
messageIds.forEach { messageId ->
|
||||
val messageValues = ContentValues().apply {
|
||||
messageValues += ContentValues().apply {
|
||||
put(MessageTable.PAYLOAD_ID, payloadId)
|
||||
put(MessageTable.MESSAGE_ID, messageId.id)
|
||||
put(MessageTable.IS_MMS, if (messageId.mms) 1 else 0)
|
||||
}
|
||||
|
||||
db.insert(MessageTable.TABLE_NAME, null, messageValues)
|
||||
}
|
||||
SqlUtil.buildBulkInsert(MessageTable.TABLE_NAME, arrayOf(MessageTable.PAYLOAD_ID, MessageTable.MESSAGE_ID, MessageTable.IS_MMS), messageValues)
|
||||
.forEach { query -> db.execSQL(query.where, query.whereArgs) }
|
||||
|
||||
db.setTransactionSuccessful()
|
||||
|
||||
return payloadId
|
||||
} finally {
|
||||
db.endTransaction()
|
||||
|
||||
@@ -20,6 +20,8 @@ import org.whispersystems.signalservice.api.push.SignalServiceAddress;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -81,33 +83,36 @@ public class SessionDatabase extends Database {
|
||||
}
|
||||
|
||||
public @NonNull List<SessionRecord> load(@NonNull List<SignalProtocolAddress> addresses) {
|
||||
SQLiteDatabase database = databaseHelper.getSignalReadableDatabase();
|
||||
List<SessionRecord> sessions = new ArrayList<>(addresses.size());
|
||||
SQLiteDatabase database = databaseHelper.getSignalReadableDatabase();
|
||||
String query = ADDRESS + " = ? AND " + DEVICE + " = ?";
|
||||
List<String[]> args = new ArrayList<>(addresses.size());
|
||||
|
||||
database.beginTransaction();
|
||||
try {
|
||||
String[] projection = new String[] { RECORD };
|
||||
String query = ADDRESS + " = ? AND " + DEVICE + " = ?";
|
||||
HashMap<SignalProtocolAddress, SessionRecord> sessions = new LinkedHashMap<>(addresses.size());
|
||||
|
||||
for (SignalProtocolAddress address : addresses) {
|
||||
String[] args = SqlUtil.buildArgs(address.getName(), address.getDeviceId());
|
||||
for (SignalProtocolAddress address : addresses) {
|
||||
args.add(SqlUtil.buildArgs(address.getName(), address.getDeviceId()));
|
||||
sessions.put(address, null);
|
||||
}
|
||||
|
||||
try (Cursor cursor = database.query(TABLE_NAME, projection, query, args, null, null, null)) {
|
||||
if (cursor.moveToFirst()) {
|
||||
try {
|
||||
sessions.add(new SessionRecord(cursor.getBlob(cursor.getColumnIndexOrThrow(RECORD))));
|
||||
} catch (IOException e) {
|
||||
Log.w(TAG, e);
|
||||
}
|
||||
String[] projection = new String[] { ADDRESS, DEVICE, RECORD };
|
||||
|
||||
for (SqlUtil.Query combinedQuery : SqlUtil.buildCustomCollectionQuery(query, args)) {
|
||||
try (Cursor cursor = database.query(TABLE_NAME, projection, combinedQuery.getWhere(), combinedQuery.getWhereArgs(), null, null, null)) {
|
||||
while (cursor.moveToNext()) {
|
||||
String address = CursorUtil.requireString(cursor, ADDRESS);
|
||||
int device = CursorUtil.requireInt(cursor, DEVICE);
|
||||
|
||||
try {
|
||||
SessionRecord record = new SessionRecord(cursor.getBlob(cursor.getColumnIndexOrThrow(RECORD)));
|
||||
sessions.put(new SignalProtocolAddress(address, device), record);
|
||||
} catch (IOException e) {
|
||||
Log.w(TAG, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
database.setTransactionSuccessful();
|
||||
} finally {
|
||||
database.endTransaction();
|
||||
}
|
||||
|
||||
return sessions;
|
||||
return new ArrayList<>(sessions.values());
|
||||
}
|
||||
|
||||
public @NonNull List<SessionRow> getAllFor(@NonNull String addressName) {
|
||||
|
||||
Reference in New Issue
Block a user