Don't churn IO on persisting roster

Stephen Paul Weber created

Especially during start up, syncRoster can get called a *lot*.  We already avoid
doing them in parallel, but they can happen one right after the other, locking
up the DB and churning IO.

Now, after we persist the roster, wait for 500ms before giving the next persist
a chance to run.  That way, other stuff has 500ms to get work done and we lose
very little DB consistency in the case of a failure.

Change summary

src/main/java/eu/siacs/conversations/services/XmppConnectionService.java | 7 
1 file changed, 5 insertions(+), 2 deletions(-)

Detailed changes

src/main/java/eu/siacs/conversations/services/XmppConnectionService.java 🔗

@@ -2041,8 +2041,11 @@ public class XmppConnectionService extends Service {
 
 
     public void syncRoster(final Account account) {
-        unregisterPhoneAccounts(account);
-        mRosterSyncTaskManager.execute(account, () -> databaseBackend.writeRoster(account.getRoster()));
+        mRosterSyncTaskManager.execute(account, () -> {
+            unregisterPhoneAccounts(account);
+            databaseBackend.writeRoster(account.getRoster());
+            try { Thread.sleep(500); } catch (InterruptedException e) { }
+        });
     }
 
     public List<Conversation> getConversations() {