Avoid unnecessary DB queries when starting clients.

This commit is contained in:
akwizgran
2018-01-07 11:24:41 +00:00
parent d2d3ccf68d
commit f1c027fa4d
11 changed files with 235 additions and 84 deletions

View File

@@ -63,6 +63,7 @@ class TransportPropertyManagerImpl implements TransportPropertyManager,
@Override
public void createLocalState(Transaction txn) throws DbException {
if (db.containsGroup(txn, localGroup.getId())) return;
db.addGroup(txn, localGroup);
// Ensure we've set things up for any pre-existing contacts
for (Contact c : db.getContacts(txn)) addingContact(txn, c);

View File

@@ -94,6 +94,8 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
Group contactGroup1 = getGroup(), contactGroup2 = getGroup();
context.checking(new Expectations() {{
oneOf(db).containsGroup(txn, localGroup.getId());
will(returnValue(false));
oneOf(db).addGroup(txn, localGroup);
oneOf(db).getContacts(txn);
will(returnValue(contacts));
@@ -123,7 +125,21 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
}
@Test
public void testCreatesGroupWhenAddingContact() throws Exception {
public void testDoesNotCreateGroupsAtStartupIfAlreadyCreated()
throws Exception {
Transaction txn = new Transaction(null, false);
context.checking(new Expectations() {{
oneOf(db).containsGroup(txn, localGroup.getId());
will(returnValue(true));
}});
TransportPropertyManagerImpl t = createInstance();
t.createLocalState(txn);
}
@Test
public void testCreatesContactGroupWhenAddingContact() throws Exception {
Transaction txn = new Transaction(null, false);
Contact contact = getContact(true);
Group contactGroup = getGroup();