diff options
author | Christian Schneppe <christian.schneppe@pix-art.de> | 2020-01-02 11:43:01 +0100 |
---|---|---|
committer | Christian Schneppe <christian.schneppe@pix-art.de> | 2020-01-02 11:43:01 +0100 |
commit | 93519d73096d23d57bd66939616c0e8042fc9a97 (patch) | |
tree | f7635b9df258c65c20160c49860a69de2c9b842d /src/main | |
parent | 5aa52b08245f64507ddfc2630b4600bf7cb123ab (diff) |
startup performance improvements
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/de/pixart/messenger/services/XmppConnectionService.java | 55 |
1 files changed, 31 insertions, 24 deletions
diff --git a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java index 038e4f235..41e4a862a 100644 --- a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java +++ b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java @@ -417,7 +417,6 @@ public class XmppConnectionService extends Service { Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": couldn't start OTR with " + conversation.getContact().getJid() + " when needed"); } sendUnsentMessages(conversation); - resendFailedFileMessages(conversation); } } final List<Conversation> pendingLeaves; @@ -804,29 +803,31 @@ public class XmppConnectionService extends Service { } private void deleteWebpreviewCache() { - try { - long start = SystemClock.elapsedRealtime(); - final Calendar time = Calendar.getInstance(); - time.add(Calendar.DAY_OF_YEAR, -7); - final File directory = new File(getCacheDir().getAbsolutePath(), File.separator + RICH_LINK_METADATA); - if (!directory.exists()) { - return; - } - final File[] files = directory.listFiles(); - if (files != null) { - int count = 0; - for (File file : files) { - Date lastModified = new Date(file.lastModified()); - if (lastModified.before(time.getTime())) { - file.delete(); - count++; + new Thread(() -> { + try { + long start = SystemClock.elapsedRealtime(); + final Calendar time = Calendar.getInstance(); + time.add(Calendar.DAY_OF_YEAR, -7); + final File directory = new File(getCacheDir().getAbsolutePath(), File.separator + RICH_LINK_METADATA); + if (!directory.exists()) { + return; + } + final File[] files = directory.listFiles(); + if (files != null) { + int count = 0; + for (File file : files) { + Date lastModified = new Date(file.lastModified()); + if (lastModified.before(time.getTime())) { + file.delete(); + count++; + } } + Log.d(Config.LOGTAG, "Deleted " + count + " expired webpreview cache files in " + (SystemClock.elapsedRealtime() - start) + "ms"); } - Log.d(Config.LOGTAG, "Deleted " + count + " expired webpreview cache files in " + (SystemClock.elapsedRealtime() - start) + "ms"); + } catch (Exception e) { + Log.d(Config.LOGTAG, "Deleted no expired webpreview cache files because of " + e); } - } catch (Exception e) { - Log.d(Config.LOGTAG, "Deleted no expired webpreview cache files because of " + e); - } + }).start(); } private boolean processAccountState(Account account, boolean interactive, boolean isUiAction, boolean isAccountPushed, HashSet<Account> pingCandidates) { @@ -1775,7 +1776,9 @@ public class XmppConnectionService extends Service { } private void sendUnsentMessages(final Conversation conversation) { - conversation.findWaitingMessages(message -> resendMessage(message, true)); + new Thread(() -> { + conversation.findWaitingMessages(message -> resendMessage(message, true)); + }).start(); } private void resendFailedFileMessages(final Conversation conversation) { @@ -2017,14 +2020,18 @@ public class XmppConnectionService extends Service { final long startMessageRestore = SystemClock.elapsedRealtime(); final Conversation quickLoad = QuickLoader.get(this.conversations); if (quickLoad != null) { - restoreMessages(quickLoad); + new Thread(() -> { + restoreMessages(quickLoad); + }).start(); updateConversationUi(); final long diffMessageRestore = SystemClock.elapsedRealtime() - startMessageRestore; Log.d(Config.LOGTAG, "quickly restored " + quickLoad.getName() + " after " + diffMessageRestore + "ms"); } for (Conversation conversation : this.conversations) { if (quickLoad != conversation) { - restoreMessages(conversation); + new Thread(() -> { + restoreMessages(conversation); + }).start(); } } mNotificationService.finishBacklog(false); |