chibenwa commented on code in PR #997:
URL: https://github.com/apache/james-project/pull/997#discussion_r878971502
##########
mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraDeletedMessageDAO.java:
##########
@@ -123,12 +127,47 @@ public Mono<Void> addDeleted(CassandraId cassandraId,
MessageUid uid) {
.setLong(UID, uid.asLong()));
}
+ public Mono<Void> addDeleted(CassandraId cassandraId,
Collection<MessageUid> uids) {
+ if (uids.size() == 1) {
+ return cassandraAsyncExecutor.executeVoid(
+ addStatement.bind()
+ .setUUID(MAILBOX_ID, cassandraId.asUuid())
+ .setLong(UID, uids.iterator().next().asLong()));
+ } else {
+ return Flux.fromIterable(uids)
+ .window(BATCH_STATEMENT_WINDOW)
+ .flatMap(partialUidsFlux -> partialUidsFlux.reduce(new
BatchStatement(BatchStatement.Type.UNLOGGED), (batch, uid) ->
+ batch.add(addStatement.bind()
+ .setUUID(MAILBOX_ID, cassandraId.asUuid())
+ .setLong(UID, uid.asLong()))))
+ .flatMap(cassandraAsyncExecutor::executeVoid)
Review Comment:
Executing 128 batches in parallel sounds like a bad idea. concatMap maybe?
or flatMap with a really low concurrency?
##########
mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraDeletedMessageDAO.java:
##########
@@ -123,12 +127,47 @@ public Mono<Void> addDeleted(CassandraId cassandraId,
MessageUid uid) {
.setLong(UID, uid.asLong()));
}
+ public Mono<Void> addDeleted(CassandraId cassandraId,
Collection<MessageUid> uids) {
+ if (uids.size() == 1) {
+ return cassandraAsyncExecutor.executeVoid(
+ addStatement.bind()
+ .setUUID(MAILBOX_ID, cassandraId.asUuid())
+ .setLong(UID, uids.iterator().next().asLong()));
+ } else {
+ return Flux.fromIterable(uids)
+ .window(BATCH_STATEMENT_WINDOW)
+ .flatMap(partialUidsFlux -> partialUidsFlux.reduce(new
BatchStatement(BatchStatement.Type.UNLOGGED), (batch, uid) ->
+ batch.add(addStatement.bind()
+ .setUUID(MAILBOX_ID, cassandraId.asUuid())
+ .setLong(UID, uid.asLong()))))
Review Comment:
We IMO do not need a Flux to build the batch statements.
```
Stream<BatchStatement> batches = Lists.partition(uids, 1024)
.stream()
.map(uidBatch -> {
BatchStatement batch = new
BatchStatement(BatchStatement.Type.UNLOGGED);
uidBatch.forEach(uid -> batch.add(addStatement.bind()
.setUUID(MAILBOX_ID, cassandraId.asUuid())
.setLong(UID, uid.asLong()))));
return batch;
});
return Flux.fromStream(batches)
.concatMap(cassandraAsyncExecutor::executeVoid)
.then();
```
Rationals: being asynchronous is not needed when building the batches...
`window` operator likely is expensive.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]