mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-16 12:49:55 +01:00
Pass message IDs to cleanup hooks in batches.
This commit is contained in:
@@ -7,6 +7,8 @@ import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
|||||||
import org.briarproject.bramble.api.sync.GroupId;
|
import org.briarproject.bramble.api.sync.GroupId;
|
||||||
import org.briarproject.bramble.api.sync.MessageId;
|
import org.briarproject.bramble.api.sync.MessageId;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An interface for registering a hook with the {@link CleanupManager}
|
* An interface for registering a hook with the {@link CleanupManager}
|
||||||
* that will be called when a message's cleanup deadline is reached.
|
* that will be called when a message's cleanup deadline is reached.
|
||||||
@@ -15,12 +17,10 @@ import org.briarproject.bramble.api.sync.MessageId;
|
|||||||
public interface CleanupHook {
|
public interface CleanupHook {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when a message's cleanup deadline is reached. If this method
|
* Called when the cleanup deadlines of one or more messages are reached.
|
||||||
* returns true, a {@link MessagesCleanedUpEvent} will be broadcast.
|
* When this method returns, a {@link MessagesCleanedUpEvent} will be
|
||||||
*
|
* broadcast.
|
||||||
* @return True if the message has been deleted, or false if it has not,
|
|
||||||
* in which case the message's cleanup timer will be stopped
|
|
||||||
*/
|
*/
|
||||||
boolean deleteMessage(Transaction txn, GroupId g, MessageId m)
|
void deleteMessages(Transaction txn, GroupId g,
|
||||||
throws DbException;
|
Collection<MessageId> messageIds) throws DbException;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -137,6 +137,7 @@ class CleanupManagerImpl implements CleanupManager, Service, EventListener {
|
|||||||
if (LOG.isLoggable(INFO)) {
|
if (LOG.isLoggable(INFO)) {
|
||||||
LOG.info(messageIds.size() + " messages to delete");
|
LOG.info(messageIds.size() + " messages to delete");
|
||||||
}
|
}
|
||||||
|
for (MessageId m : messageIds) db.stopCleanupTimer(txn, m);
|
||||||
Group group = db.getGroup(txn, groupId);
|
Group group = db.getGroup(txn, groupId);
|
||||||
ClientMajorVersion cv = new ClientMajorVersion(group.getClientId(),
|
ClientMajorVersion cv = new ClientMajorVersion(group.getClientId(),
|
||||||
group.getMajorVersion());
|
group.getMajorVersion());
|
||||||
@@ -144,10 +145,7 @@ class CleanupManagerImpl implements CleanupManager, Service, EventListener {
|
|||||||
if (hook == null) {
|
if (hook == null) {
|
||||||
throw new IllegalStateException("No cleanup hook for " + cv);
|
throw new IllegalStateException("No cleanup hook for " + cv);
|
||||||
}
|
}
|
||||||
for (MessageId m : messageIds) {
|
hook.deleteMessages(txn, groupId, messageIds);
|
||||||
hook.deleteMessage(txn, groupId, m);
|
|
||||||
db.stopCleanupTimer(txn, m);
|
|
||||||
}
|
|
||||||
txn.attach(new MessagesCleanedUpEvent(groupId, messageIds));
|
txn.attach(new MessagesCleanedUpEvent(groupId, messageIds));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user