diff options
author | Christian Schneppe <christian@pix-art.de> | 2019-05-09 21:47:50 +0200 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2019-05-18 00:01:57 +0200 |
commit | 294144943429503f62675d23b9911d43c0f41ce3 (patch) | |
tree | 6ca73458e72a8afe0a148f8971726eeb7311ea71 /src/main | |
parent | 5b75d52d444d6cda368e85f5884163e229451ece (diff) |
performance improvements
Diffstat (limited to 'src/main')
7 files changed, 43 insertions, 28 deletions
diff --git a/src/main/java/de/pixart/messenger/Config.java b/src/main/java/de/pixart/messenger/Config.java index 171af1053..3bc7f6ef7 100644 --- a/src/main/java/de/pixart/messenger/Config.java +++ b/src/main/java/de/pixart/messenger/Config.java @@ -103,7 +103,7 @@ public final class Config { public static final int MAX_NUM_PAGES = 3; public static final int MAX_SEARCH_RESULTS = 300; - public static final int REFRESH_UI_INTERVAL = 250; + public static final int REFRESH_UI_INTERVAL = 500; public static final long OMEMO_AUTO_EXPIRY = 14 * MILLISECONDS_IN_DAY; // delete old OMEMO devices after 14 days of inactivity public static final boolean REMOVE_BROKEN_DEVICES = false; diff --git a/src/main/java/de/pixart/messenger/entities/Conversation.java b/src/main/java/de/pixart/messenger/entities/Conversation.java index 7e1a9e91a..8104e5ab1 100644 --- a/src/main/java/de/pixart/messenger/entities/Conversation.java +++ b/src/main/java/de/pixart/messenger/entities/Conversation.java @@ -207,7 +207,7 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl } } } - for(Message result : results) { + for (Message result : results) { onMessageFound.onMessageFound(result); } } @@ -343,7 +343,7 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl } } } - for(Message result : results) { + for (Message result : results) { onMessageFound.onMessageFound(result); } } @@ -568,7 +568,8 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl } } - public @NonNull CharSequence getName() { + public @NonNull + CharSequence getName() { if (getMode() == MODE_MULTI) { final String roomName = getMucOptions().getName(); final String subject = getMucOptions().getSubject(); @@ -933,12 +934,12 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl continue; //it's unsafe to use private messages as anchor. They could be coming from user archive } if (message.getStatus() == Message.STATUS_RECEIVED || message.isCarbon() || message.getServerMsgId() != null) { - lastReceived = new MamReference(message.getTimeSent(),message.getServerMsgId()); + lastReceived = new MamReference(message.getTimeSent(), message.getServerMsgId()); break; } } } - return MamReference.max(lastClear,lastReceived); + return MamReference.max(lastClear, lastReceived); } public void setMutedTill(long value) { @@ -1131,7 +1132,7 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl for (int i = this.messages.size() - 1; i >= 0; --i) { Message message = this.messages.get(i); if ((message.getType() == Message.TYPE_IMAGE || message.getType() == Message.TYPE_FILE) && message.getEncryption() != Message.ENCRYPTION_PGP) { - if (message.getStatus() == Message.STATUS_SEND_FAILED && !message.isFileDeleted() && message.needsUploading()){ + if (message.getStatus() == Message.STATUS_SEND_FAILED && !message.isFileDeleted() && message.needsUploading()) { ++count; } } diff --git a/src/main/java/de/pixart/messenger/entities/Message.java b/src/main/java/de/pixart/messenger/entities/Message.java index 89236b0fd..9d23d5461 100644 --- a/src/main/java/de/pixart/messenger/entities/Message.java +++ b/src/main/java/de/pixart/messenger/entities/Message.java @@ -313,6 +313,7 @@ public class Message extends AbstractEntity implements AvatarService.Avatarable this.body = body; this.isGeoUri = null; this.isXmppUri = null; + this.isWebUri = null; this.isEmojisOnly = null; this.treatAsDownloadable = null; this.fileParams = null; diff --git a/src/main/java/de/pixart/messenger/parser/MessageParser.java b/src/main/java/de/pixart/messenger/parser/MessageParser.java index d67e84371..2c81380dc 100644 --- a/src/main/java/de/pixart/messenger/parser/MessageParser.java +++ b/src/main/java/de/pixart/messenger/parser/MessageParser.java @@ -312,8 +312,10 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece if (account.getXmppConnection().getFeatures().bookmarksConversion()) { final Element i = items.findChild("item"); final Element storage = i == null ? null : i.findChild("storage", Namespace.BOOKMARKS); - mXmppConnectionService.processBookmarks(account, storage, true); - Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": processing bookmark PEP event"); + new Thread(() -> { + mXmppConnectionService.processBookmarks(account, storage, true); + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": processing bookmark PEP event"); + }).start(); } else { Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": ignoring bookmark PEP event because bookmark conversion was not detected"); } diff --git a/src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java b/src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java index 6fc6d7569..3bf332c92 100644 --- a/src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java +++ b/src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java @@ -1097,13 +1097,15 @@ public class DatabaseBackend extends SQLiteOpenHelper { } public void expireOldMessages(long timestamp) { + long start = SystemClock.elapsedRealtime(); final String[] args = {String.valueOf(timestamp)}; SQLiteDatabase db = this.getReadableDatabase(); db.beginTransaction(); db.delete("messages_index", "uuid in (select uuid from messages where timeSent<?)", args); - db.delete(Message.TABLENAME, "timeSent<?", args); + int num = db.delete(Message.TABLENAME, "timeSent<?", args); db.setTransactionSuccessful(); db.endTransaction(); + Log.d(Config.LOGTAG, "deleted " + num + " expired messages in " + (SystemClock.elapsedRealtime() - start) + "ms"); } public MamReference getLastMessageReceived(Account account) { diff --git a/src/main/java/de/pixart/messenger/persistance/FileBackend.java b/src/main/java/de/pixart/messenger/persistance/FileBackend.java index 3eaa9e406..33a524894 100644 --- a/src/main/java/de/pixart/messenger/persistance/FileBackend.java +++ b/src/main/java/de/pixart/messenger/persistance/FileBackend.java @@ -589,12 +589,17 @@ public class FileBackend { } public Bitmap getThumbnail(Message message, int size, boolean cacheOnly) throws IOException { - final String uuid = message.getUuid(); + // The key for getting a cached thumbnail contains the UUID and the size + // since this method is used for thumbnails of (bigger) normal image messages and (smaller) image message references. + // If only the UUID were used, the first loaded thumbnail would be cached and the next loading + // would get that thumbnail which would have the size of the first cached thumbnail + // possibly leading to undesirable appearance of the displayed thumbnail. + final String key = message.getUuid() + String.valueOf(size);final String uuid = message.getUuid(); final LruCache<String, Bitmap> cache = mXmppConnectionService.getBitmapCache(); - Bitmap thumbnail = cache.get(uuid); + Bitmap thumbnail = cache.get(key ); if ((thumbnail == null) && (!cacheOnly)) { synchronized (THUMBNAIL_LOCK) { - thumbnail = cache.get(uuid); + thumbnail = cache.get(key ); if (thumbnail != null) { return thumbnail; } @@ -616,7 +621,7 @@ public class FileBackend { thumbnail = withGifOverlay; } } - cache.put(uuid, thumbnail); + cache.put(key , thumbnail); } } return thumbnail; diff --git a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java index d9be63dd7..408ad5a8f 100644 --- a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java +++ b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java @@ -78,7 +78,6 @@ import java.util.Set; import java.util.WeakHashMap; import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.CountDownLatch; -import java.util.concurrent.Executors; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicLong; @@ -111,7 +110,6 @@ import de.pixart.messenger.generator.MessageGenerator; import de.pixart.messenger.generator.PresenceGenerator; import de.pixart.messenger.http.CustomURLStreamHandlerFactory; import de.pixart.messenger.http.HttpConnectionManager; -import de.pixart.messenger.http.services.MuclumbusService; import de.pixart.messenger.parser.AbstractParser; import de.pixart.messenger.parser.IqParser; import de.pixart.messenger.parser.MessageParser; @@ -164,8 +162,6 @@ import de.pixart.messenger.xmpp.stanzas.IqPacket; import de.pixart.messenger.xmpp.stanzas.MessagePacket; import de.pixart.messenger.xmpp.stanzas.PresencePacket; import me.leolin.shortcutbadger.ShortcutBadger; -import retrofit2.Retrofit; -import retrofit2.converter.gson.GsonConverterFactory; import rocks.xmpp.addr.Jid; import static de.pixart.messenger.ui.SettingsActivity.CHAT_STATES; @@ -1066,7 +1062,7 @@ public class XmppConnectionService extends Service { Runnable runnable = () -> { long timestamp = getAutomaticMessageDeletionDate(); if (timestamp > 0) { - expireOldMessages(timestamp); + expireOldMessages(timestamp, true); synchronized (XmppConnectionService.this.conversations) { for (Conversation conversation : XmppConnectionService.this.conversations) { conversation.expireOldMessages(timestamp); @@ -1758,9 +1754,9 @@ public class XmppConnectionService extends Service { public void pushBookmarks(Account account) { if (account.getXmppConnection() != null && account.getXmppConnection().getFeatures().bookmarksConversion()) { - pushBookmarksPep(account); + new Thread(() -> pushBookmarksPep(account)).start(); } else { - pushBookmarksPrivateXml(account); + new Thread(() -> pushBookmarksPrivateXml(account)).start(); } } @@ -1838,7 +1834,7 @@ public class XmppConnectionService extends Service { mLastExpiryRun.set(SystemClock.elapsedRealtime()); if (deletionDate > 0) { Log.d(Config.LOGTAG, "deleting messages that are older than " + AbstractGenerator.getTimestamp(deletionDate)); - expireOldMessages(deletionDate); + expireOldMessages(deletionDate, false); } Log.d(Config.LOGTAG, "restoring roster..."); for (Account account : accounts) { @@ -4420,7 +4416,6 @@ public class XmppConnectionService extends Service { Runnable runnable = () -> { databaseBackend.deleteMessagesInConversation(conversation); databaseBackend.updateConversation(conversation); - }; mDatabaseWriterExecutor.execute(runnable); } @@ -4809,12 +4804,21 @@ public class XmppConnectionService extends Service { } } - private void expireOldMessages(long timestamp) { - try { + private void expireOldMessages(long timestamp, boolean stepped) { + if (stepped) { + final int year = 365; + final long day = (long) 24 * 60 * 60 * 1000; + int count = 0; + while (count <= year) { + try { + databaseBackend.expireOldMessages(timestamp - ((year - count) * day)); + } catch (Exception e) { + e.printStackTrace(); + } + count++; + } + } else { databaseBackend.expireOldMessages(timestamp); - } catch (Exception e) { - e.printStackTrace(); - expireOldMessages(timestamp); } } } |