mirror of
https://github.com/signalapp/Signal-Android.git
synced 2025-12-23 04:28:35 +00:00
Alleviate database contention when archiving threads.
This commit is contained in:
committed by
Alex Hart
parent
aa0d7c218f
commit
3fca46de92
@@ -741,14 +741,13 @@ public class RecipientDatabase extends Database {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void markNeedsSync(@NonNull Collection<RecipientId> recipientIds) {
|
public void markNeedsSyncWithoutRefresh(@NonNull Collection<RecipientId> recipientIds) {
|
||||||
SQLiteDatabase db = databaseHelper.getWritableDatabase();
|
SQLiteDatabase db = databaseHelper.getWritableDatabase();
|
||||||
|
|
||||||
db.beginTransaction();
|
db.beginTransaction();
|
||||||
try {
|
try {
|
||||||
for (RecipientId recipientId : recipientIds) {
|
for (RecipientId recipientId : recipientIds) {
|
||||||
rotateStorageId(recipientId);
|
rotateStorageId(recipientId);
|
||||||
Recipient.live(recipientId).refresh();
|
|
||||||
}
|
}
|
||||||
db.setTransactionSuccessful();
|
db.setTransactionSuccessful();
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
@@ -455,23 +455,29 @@ public class ThreadDatabase extends Database {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setForcedUnread(@NonNull Collection<Long> threadIds) {
|
public void setForcedUnread(@NonNull Collection<Long> threadIds) {
|
||||||
SQLiteDatabase db = databaseHelper.getWritableDatabase();
|
SQLiteDatabase db = databaseHelper.getWritableDatabase();
|
||||||
|
List<RecipientId> recipientIds = Collections.emptyList();
|
||||||
|
|
||||||
db.beginTransaction();
|
db.beginTransaction();
|
||||||
try {
|
try {
|
||||||
List<RecipientId> recipientIds = getRecipientIdsForThreadIds(threadIds);
|
|
||||||
SqlUtil.Query query = SqlUtil.buildCollectionQuery(ID, threadIds);
|
SqlUtil.Query query = SqlUtil.buildCollectionQuery(ID, threadIds);
|
||||||
ContentValues contentValues = new ContentValues();
|
ContentValues contentValues = new ContentValues();
|
||||||
|
|
||||||
contentValues.put(READ, ReadStatus.FORCED_UNREAD.serialize());
|
contentValues.put(READ, ReadStatus.FORCED_UNREAD.serialize());
|
||||||
|
|
||||||
db.update(TABLE_NAME, contentValues, query.getWhere(), query.getWhereArgs());
|
db.update(TABLE_NAME, contentValues, query.getWhere(), query.getWhereArgs());
|
||||||
DatabaseFactory.getRecipientDatabase(context).markNeedsSync(recipientIds);
|
|
||||||
|
recipientIds = getRecipientIdsForThreadIds(threadIds);
|
||||||
|
DatabaseFactory.getRecipientDatabase(context).markNeedsSyncWithoutRefresh(recipientIds);
|
||||||
|
|
||||||
db.setTransactionSuccessful();
|
db.setTransactionSuccessful();
|
||||||
} finally {
|
} finally {
|
||||||
db.endTransaction();
|
db.endTransaction();
|
||||||
|
|
||||||
|
for (RecipientId id : recipientIds) {
|
||||||
|
Recipient.live(id).refresh();
|
||||||
|
}
|
||||||
|
|
||||||
StorageSyncHelper.scheduleSyncForDataChange();
|
StorageSyncHelper.scheduleSyncForDataChange();
|
||||||
notifyConversationListListeners();
|
notifyConversationListListeners();
|
||||||
}
|
}
|
||||||
@@ -627,7 +633,8 @@ public class ThreadDatabase extends Database {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setArchived(Set<Long> threadIds, boolean archive) {
|
public void setArchived(Set<Long> threadIds, boolean archive) {
|
||||||
SQLiteDatabase db = databaseHelper.getReadableDatabase();
|
SQLiteDatabase db = databaseHelper.getReadableDatabase();
|
||||||
|
List<RecipientId> recipientIds = Collections.emptyList();
|
||||||
|
|
||||||
db.beginTransaction();
|
db.beginTransaction();
|
||||||
try {
|
try {
|
||||||
@@ -642,12 +649,17 @@ public class ThreadDatabase extends Database {
|
|||||||
db.update(TABLE_NAME, values, ID_WHERE, SqlUtil.buildArgs(threadId));
|
db.update(TABLE_NAME, values, ID_WHERE, SqlUtil.buildArgs(threadId));
|
||||||
}
|
}
|
||||||
|
|
||||||
List<RecipientId> recipientIds = getRecipientIdsForThreadIds(threadIds);
|
recipientIds = getRecipientIdsForThreadIds(threadIds);
|
||||||
DatabaseFactory.getRecipientDatabase(context).markNeedsSync(recipientIds);
|
DatabaseFactory.getRecipientDatabase(context).markNeedsSyncWithoutRefresh(recipientIds);
|
||||||
|
|
||||||
db.setTransactionSuccessful();
|
db.setTransactionSuccessful();
|
||||||
} finally {
|
} finally {
|
||||||
db.endTransaction();
|
db.endTransaction();
|
||||||
|
|
||||||
|
for (RecipientId id : recipientIds) {
|
||||||
|
Recipient.live(id).refresh();
|
||||||
|
}
|
||||||
|
|
||||||
notifyConversationListListeners();
|
notifyConversationListListeners();
|
||||||
StorageSyncHelper.scheduleSyncForDataChange();
|
StorageSyncHelper.scheduleSyncForDataChange();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user