quantranhong1999 commented on code in PR #1925:
URL: https://github.com/apache/james-project/pull/1925#discussion_r1458330278


##########
mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/DeleteMessageListener.java:
##########
@@ -155,6 +156,13 @@ private Mono<Boolean> isUnreferenced(PostgresMessageId id, 
PostgresMailboxMessag
     }
 
     private Mono<Void> deleteAttachment(PostgresMessageId messageId, 
PostgresAttachmentDAO attachmentDAO) {
-        return attachmentDAO.deleteByMessageId(messageId);
+        return deleteAttachmentReference(messageId, attachmentDAO)
+            .then(attachmentDAO.deleteByMessageId(messageId));
+    }
+
+    private Mono<Void> deleteAttachmentReference(PostgresMessageId messageId, 
PostgresAttachmentDAO attachmentDAO) {

Review Comment:
   `deleteAttachmentBlobs` is better?



##########
mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/DeleteMessageListenerContract.java:
##########
@@ -167,4 +181,47 @@ void 
deleteMessageInMailboxShouldNotDeleteReferencedMessageMetadata() throws Exc
                 .isNotEmpty();
         });
     }
+
+    @Test
+    void deleteMessageShouldDeleteReferenceBlob() throws Exception {
+        assumeTrue(!(blobStore instanceof DeDuplicationBlobStore));
+
+        MessageManager.AppendResult appendResult = 
inboxManager.appendMessage(MessageManager.AppendCommand.builder()
+            
.build(ClassLoaderUtils.getSystemResourceAsByteArray("eml/emailWithOnlyAttachment.eml")),
 session);
+        AttachmentId attachmentId = 
appendResult.getMessageAttachments().get(0).getAttachment().getAttachmentId();
+
+        BlobId attachmentBlobId = 
attachmentDAO.getAttachment(attachmentId).block().getRight();
+        BlobId messageBodyBlobId = 
postgresMessageDAO.getBodyBlobId((PostgresMessageId) 
appendResult.getId().getMessageId()).block();
+
+        inboxManager.delete(ImmutableList.of(appendResult.getId().getUid()), 
session);
+
+        assertSoftly(softly -> {
+            softly.assertThatThrownBy(() -> 
Mono.from(blobStore.readReactive(blobStore.getDefaultBucketName(), 
attachmentBlobId)).block())
+                .isInstanceOf(ObjectNotFoundException.class);
+            softly.assertThatThrownBy(() -> 
Mono.from(blobStore.readReactive(blobStore.getDefaultBucketName(), 
messageBodyBlobId)).block())
+                .isInstanceOf(ObjectNotFoundException.class);
+        });
+    }
+
+    @Test
+    void deleteMessageShouldNotDeleteUnReferenceBlob() throws Exception {

Review Comment:
   ```suggestion
       void deleteMessageListenerShouldNotDeleteReferencedBlob() throws 
Exception {
   ```
   ?



##########
mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/DeleteMessageListenerContract.java:
##########
@@ -167,4 +181,47 @@ void 
deleteMessageInMailboxShouldNotDeleteReferencedMessageMetadata() throws Exc
                 .isNotEmpty();
         });
     }
+
+    @Test
+    void deleteMessageShouldDeleteReferenceBlob() throws Exception {

Review Comment:
   ```suggestion
       void deleteMessageListenerShouldDeleteUnreferencedBlob() throws 
Exception {
   ```



-- 
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]

Reply via email to