Reduce fetches when you open a conversation.

This commit is contained in:
Greyson Parrelli 2021-06-17 10:51:09 -04:00 committed by Cody Henthorne
parent 3c6bed90db
commit 93f37ad70f
5 changed files with 29 additions and 4 deletions

View file

@ -97,6 +97,8 @@ class ConversationDataSource implements PagedDataSource<ConversationMessage> {
records = attachmentHelper.buildUpdatedModels(context, records); records = attachmentHelper.buildUpdatedModels(context, records);
stopwatch.split("attachment-models");
List<ConversationMessage> messages = Stream.of(records) List<ConversationMessage> messages = Stream.of(records)
.map(m -> ConversationMessageFactory.createWithUnresolvedData(context, m, mentionHelper.getMentions(m.getId()))) .map(m -> ConversationMessageFactory.createWithUnresolvedData(context, m, mentionHelper.getMentions(m.getId())))
.toList(); .toList();

View file

@ -54,6 +54,14 @@ public abstract class Database {
notifyVerboseConversationListeners(threadId); notifyVerboseConversationListeners(threadId);
} }
protected void notifyVerboseConversationListeners(Set<Long> threadIds) {
ApplicationDependencies.getDatabaseObserver().notifyVerboseConversationListeners(threadIds);
for (long threadId : threadIds) {
notifyVerboseConversationListeners(threadId);
}
}
protected void notifyVerboseConversationListeners(long threadId) { protected void notifyVerboseConversationListeners(long threadId) {
ApplicationDependencies.getDatabaseObserver().notifyVerboseConversationListeners(threadId); ApplicationDependencies.getDatabaseObserver().notifyVerboseConversationListeners(threadId);
context.getContentResolver().notifyChange(DatabaseContentProviders.Conversation.getVerboseUriForThread(threadId), null); context.getContentResolver().notifyChange(DatabaseContentProviders.Conversation.getVerboseUriForThread(threadId), null);

View file

@ -112,6 +112,18 @@ public final class DatabaseObserver {
application.getContentResolver().notifyChange(DatabaseContentProviders.Conversation.getVerboseUriForThread(threadId), null); application.getContentResolver().notifyChange(DatabaseContentProviders.Conversation.getVerboseUriForThread(threadId), null);
} }
public void notifyVerboseConversationListeners(Set<Long> threadIds) {
executor.execute(() -> {
for (long threadId : threadIds) {
notifyMapped(verboseConversationObservers, threadId);
}
});
for (long threadId : threadIds) {
application.getContentResolver().notifyChange(DatabaseContentProviders.Conversation.getVerboseUriForThread(threadId), null);
}
}
public void notifyVerboseConversationListeners(long threadId) { public void notifyVerboseConversationListeners(long threadId) {
executor.execute(() -> { executor.execute(() -> {
notifyMapped(verboseConversationObservers, threadId); notifyMapped(verboseConversationObservers, threadId);

View file

@ -886,10 +886,13 @@ public class SmsDatabase extends MessageDatabase {
contentValues.put(READ, 1); contentValues.put(READ, 1);
} }
db.update(TABLE_NAME, contentValues, ID_WHERE, SqlUtil.buildArgs(record.getId())); SqlUtil.Query query = SqlUtil.buildTrueUpdateQuery(ID_WHERE, SqlUtil.buildArgs(record.getId()), contentValues);
} boolean updated = db.update(TABLE_NAME, contentValues, query.getWhere(), query.getWhereArgs()) > 0;
notifyConversationListeners(threadId); if (updated) {
notifyConversationListeners(threadId);
}
}
return sameEraId; return sameEraId;
} }

View file

@ -430,7 +430,7 @@ public class ThreadDatabase extends Database {
db.endTransaction(); db.endTransaction();
} }
notifyConversationListeners(threadIdToSinceTimestamp.keySet()); notifyVerboseConversationListeners(threadIdToSinceTimestamp.keySet());
notifyConversationListListeners(); notifyConversationListListeners();
if (needsSync) { if (needsSync) {