mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-20 22:59:54 +01:00
Completely remove old local updates from the database.
This commit is contained in:
@@ -122,8 +122,9 @@ public interface DatabaseComponent {
|
|||||||
throws DbException;
|
throws DbException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes the message with the given ID. The message ID and any other
|
* Deletes the message with the given ID. Unlike
|
||||||
* associated data are not deleted.
|
* {@link #removeMessage(Transaction, MessageId)}, the message ID and any
|
||||||
|
* other associated data are not deleted.
|
||||||
*/
|
*/
|
||||||
void deleteMessage(Transaction txn, MessageId m) throws DbException;
|
void deleteMessage(Transaction txn, MessageId m) throws DbException;
|
||||||
|
|
||||||
@@ -452,6 +453,11 @@ public interface DatabaseComponent {
|
|||||||
*/
|
*/
|
||||||
void removeLocalAuthor(Transaction txn, AuthorId a) throws DbException;
|
void removeLocalAuthor(Transaction txn, AuthorId a) throws DbException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes a message (and all associated state) from the database.
|
||||||
|
*/
|
||||||
|
void removeMessage(Transaction txn, MessageId m) throws DbException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes a transport (and all associated state) from the database.
|
* Removes a transport (and all associated state) from the database.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -770,6 +770,16 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
|
|||||||
transaction.attach(new LocalAuthorRemovedEvent(a));
|
transaction.attach(new LocalAuthorRemovedEvent(a));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void removeMessage(Transaction transaction, MessageId m)
|
||||||
|
throws DbException {
|
||||||
|
if (transaction.isReadOnly()) throw new IllegalArgumentException();
|
||||||
|
T txn = unbox(transaction);
|
||||||
|
if (!db.containsMessage(txn, m))
|
||||||
|
throw new NoSuchMessageException();
|
||||||
|
db.removeMessage(txn, m);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeTransport(Transaction transaction, TransportId t)
|
public void removeTransport(Transaction transaction, TransportId t)
|
||||||
throws DbException {
|
throws DbException {
|
||||||
|
|||||||
@@ -269,10 +269,8 @@ class TransportPropertyManagerImpl implements TransportPropertyManager,
|
|||||||
storeMessage(txn, localGroup.getId(), t, merged, version,
|
storeMessage(txn, localGroup.getId(), t, merged, version,
|
||||||
true, false);
|
true, false);
|
||||||
// Delete the previous update, if any
|
// Delete the previous update, if any
|
||||||
if (latest != null) {
|
if (latest != null)
|
||||||
db.deleteMessage(txn, latest.messageId);
|
db.removeMessage(txn, latest.messageId);
|
||||||
db.deleteMessageMetadata(txn, latest.messageId);
|
|
||||||
}
|
|
||||||
// Store the merged properties in each contact's group
|
// Store the merged properties in each contact's group
|
||||||
for (Contact c : db.getContacts(txn)) {
|
for (Contact c : db.getContacts(txn)) {
|
||||||
Group g = getContactGroup(c);
|
Group g = getContactGroup(c);
|
||||||
@@ -281,10 +279,8 @@ class TransportPropertyManagerImpl implements TransportPropertyManager,
|
|||||||
storeMessage(txn, g.getId(), t, merged, version,
|
storeMessage(txn, g.getId(), t, merged, version,
|
||||||
true, true);
|
true, true);
|
||||||
// Delete the previous update, if any
|
// Delete the previous update, if any
|
||||||
if (latest != null) {
|
if (latest != null)
|
||||||
db.deleteMessage(txn, latest.messageId);
|
db.removeMessage(txn, latest.messageId);
|
||||||
db.deleteMessageMetadata(txn, latest.messageId);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
db.commitTransaction(txn);
|
db.commitTransaction(txn);
|
||||||
@@ -338,13 +334,11 @@ class TransportPropertyManagerImpl implements TransportPropertyManager,
|
|||||||
latestUpdates.put(t, new LatestUpdate(e.getKey(), version));
|
latestUpdates.put(t, new LatestUpdate(e.getKey(), version));
|
||||||
} else if (version > latest.version) {
|
} else if (version > latest.version) {
|
||||||
// This update is newer - delete the previous one
|
// This update is newer - delete the previous one
|
||||||
db.deleteMessage(txn, latest.messageId);
|
db.removeMessage(txn, latest.messageId);
|
||||||
db.deleteMessageMetadata(txn, latest.messageId);
|
|
||||||
latestUpdates.put(t, new LatestUpdate(e.getKey(), version));
|
latestUpdates.put(t, new LatestUpdate(e.getKey(), version));
|
||||||
} else {
|
} else {
|
||||||
// We've already found a newer update - delete this one
|
// We've already found a newer update - delete this one
|
||||||
db.deleteMessage(txn, e.getKey());
|
db.removeMessage(txn, e.getKey());
|
||||||
db.deleteMessageMetadata(txn, e.getKey());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return latestUpdates;
|
return latestUpdates;
|
||||||
@@ -366,13 +360,21 @@ class TransportPropertyManagerImpl implements TransportPropertyManager,
|
|||||||
latest = new LatestUpdate(e.getKey(), version);
|
latest = new LatestUpdate(e.getKey(), version);
|
||||||
} else if (version > latest.version) {
|
} else if (version > latest.version) {
|
||||||
// This update is newer - delete the previous one
|
// This update is newer - delete the previous one
|
||||||
db.deleteMessage(txn, latest.messageId);
|
if (local) {
|
||||||
db.deleteMessageMetadata(txn, latest.messageId);
|
db.removeMessage(txn, latest.messageId);
|
||||||
|
} else {
|
||||||
|
db.deleteMessage(txn, latest.messageId);
|
||||||
|
db.deleteMessageMetadata(txn, latest.messageId);
|
||||||
|
}
|
||||||
latest = new LatestUpdate(e.getKey(), version);
|
latest = new LatestUpdate(e.getKey(), version);
|
||||||
} else {
|
} else {
|
||||||
// We've already found a newer update - delete this one
|
// We've already found a newer update - delete this one
|
||||||
db.deleteMessage(txn, e.getKey());
|
if (local) {
|
||||||
db.deleteMessageMetadata(txn, e.getKey());
|
db.removeMessage(txn, e.getKey());
|
||||||
|
} else {
|
||||||
|
db.deleteMessage(txn, e.getKey());
|
||||||
|
db.deleteMessageMetadata(txn, e.getKey());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -587,8 +587,7 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
|
|||||||
expectStoreMessage(txn, localGroup.getId(), "foo",
|
expectStoreMessage(txn, localGroup.getId(), "foo",
|
||||||
fooPropertiesDict, 2, true, false);
|
fooPropertiesDict, 2, true, false);
|
||||||
// Delete the previous update
|
// Delete the previous update
|
||||||
oneOf(db).deleteMessage(txn, localGroupUpdateId);
|
oneOf(db).removeMessage(txn, localGroupUpdateId);
|
||||||
oneOf(db).deleteMessageMetadata(txn, localGroupUpdateId);
|
|
||||||
// Store the merged properties in each contact's group, version 2
|
// Store the merged properties in each contact's group, version 2
|
||||||
oneOf(db).getContacts(txn);
|
oneOf(db).getContacts(txn);
|
||||||
will(returnValue(Collections.singletonList(contact)));
|
will(returnValue(Collections.singletonList(contact)));
|
||||||
@@ -600,8 +599,7 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
|
|||||||
expectStoreMessage(txn, contactGroup.getId(), "foo",
|
expectStoreMessage(txn, contactGroup.getId(), "foo",
|
||||||
fooPropertiesDict, 2, true, true);
|
fooPropertiesDict, 2, true, true);
|
||||||
// Delete the previous update
|
// Delete the previous update
|
||||||
oneOf(db).deleteMessage(txn, contactGroupUpdateId);
|
oneOf(db).removeMessage(txn, contactGroupUpdateId);
|
||||||
oneOf(db).deleteMessageMetadata(txn, contactGroupUpdateId);
|
|
||||||
oneOf(db).commitTransaction(txn);
|
oneOf(db).commitTransaction(txn);
|
||||||
oneOf(db).endTransaction(txn);
|
oneOf(db).endTransaction(txn);
|
||||||
}});
|
}});
|
||||||
@@ -676,10 +674,8 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
|
|||||||
oneOf(clientHelper).getMessageMetadataAsDictionary(txn,
|
oneOf(clientHelper).getMessageMetadataAsDictionary(txn,
|
||||||
localGroup.getId());
|
localGroup.getId());
|
||||||
will(returnValue(messageMetadata));
|
will(returnValue(messageMetadata));
|
||||||
oneOf(db).deleteMessage(txn, barVersion1);
|
oneOf(db).removeMessage(txn, barVersion1);
|
||||||
oneOf(db).deleteMessageMetadata(txn, barVersion1);
|
oneOf(db).removeMessage(txn, barVersion2);
|
||||||
oneOf(db).deleteMessage(txn, barVersion2);
|
|
||||||
oneOf(db).deleteMessageMetadata(txn, barVersion2);
|
|
||||||
// Retrieve and parse the latest local properties
|
// Retrieve and parse the latest local properties
|
||||||
oneOf(clientHelper).getMessageAsList(txn, fooVersion999);
|
oneOf(clientHelper).getMessageAsList(txn, fooVersion999);
|
||||||
will(returnValue(fooUpdate));
|
will(returnValue(fooUpdate));
|
||||||
|
|||||||
Reference in New Issue
Block a user