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


##########
mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/mail/AttachmentLoader.java:
##########
@@ -0,0 +1,69 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.mailbox.postgres.mail;
+
+import static 
org.apache.james.mailbox.postgres.mail.PostgresMessageModule.MessageTable.ATTACHMENT_METADATA;
+
+import org.apache.commons.lang3.tuple.Pair;
+import org.apache.james.mailbox.model.AttachmentMetadata;
+import org.apache.james.mailbox.model.MessageAttachmentMetadata;
+import org.apache.james.mailbox.store.mail.MessageMapper;
+import org.apache.james.mailbox.store.mail.model.impl.SimpleMailboxMessage;
+import org.jooq.Record;
+
+import reactor.core.publisher.Flux;
+import reactor.core.publisher.Mono;
+
+public class AttachmentLoader {
+
+    private final PostgresAttachmentMapper attachmentMapper;
+
+    public AttachmentLoader(PostgresAttachmentMapper attachmentMapper) {
+        this.attachmentMapper = attachmentMapper;
+    }
+
+
+    public Flux<Pair<SimpleMailboxMessage.Builder, Record>> 
addAttachmentToMessage(Flux<Pair<SimpleMailboxMessage.Builder, Record>> 
findMessagePublisher, MessageMapper.FetchType fetchType) {
+        return findMessagePublisher.flatMap(pair -> {
+            if (fetchType == MessageMapper.FetchType.FULL || fetchType == 
MessageMapper.FetchType.ATTACHMENTS_METADATA) {

Review Comment:
   Need concurrency control IMO



##########
mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/mail/PostgresAttachmentModule.java:
##########
@@ -0,0 +1,58 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.mailbox.postgres.mail;
+
+import java.util.UUID;
+
+import org.apache.james.backends.postgres.PostgresModule;
+import org.apache.james.backends.postgres.PostgresTable;
+import org.jooq.Field;
+import org.jooq.Record;
+import org.jooq.Table;
+import org.jooq.impl.DSL;
+import org.jooq.impl.SQLDataType;
+
+public interface PostgresAttachmentModule {
+
+    interface PostgresAttachmentTable {
+
+        Table<Record> TABLE_NAME = DSL.table("attachment");
+        Field<UUID> ID = DSL.field("id", SQLDataType.UUID.notNull());
+        Field<String> BLOB_ID = DSL.field("blob_id", SQLDataType.VARCHAR);
+        Field<String> TYPE = DSL.field("type", SQLDataType.VARCHAR);
+        Field<UUID> MESSAGE_ID = DSL.field("message_id", SQLDataType.UUID);
+        Field<Long> SIZE = DSL.field("size", SQLDataType.BIGINT);
+
+        PostgresTable TABLE = PostgresTable.name(TABLE_NAME.getName())
+            .createTableStep(((dsl, tableName) -> 
dsl.createTableIfNotExists(tableName)
+                .column(ID, SQLDataType.UUID)

Review Comment:
   ```suggestion
                   .column(ID)
   ```
   is enough?



##########
mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/mail/dao/PostgresAttachmentDAO.java:
##########
@@ -0,0 +1,76 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.mailbox.postgres.mail.dao;
+
+
+import org.apache.commons.lang3.tuple.Pair;
+import org.apache.james.backends.postgres.utils.PostgresExecutor;
+import org.apache.james.blob.api.BlobId;
+import org.apache.james.mailbox.model.AttachmentId;
+import org.apache.james.mailbox.model.AttachmentMetadata;
+import org.apache.james.mailbox.postgres.PostgresMessageId;
+import 
org.apache.james.mailbox.postgres.mail.PostgresAttachmentModule.PostgresAttachmentTable;
+
+import reactor.core.publisher.Flux;
+import reactor.core.publisher.Mono;
+
+public class PostgresAttachmentDAO {
+
+    private final PostgresExecutor postgresExecutor;
+    private final BlobId.Factory blobIdFactory;
+
+    public PostgresAttachmentDAO(PostgresExecutor postgresExecutor, 
BlobId.Factory blobIdFactory) {
+        this.postgresExecutor = postgresExecutor;
+        this.blobIdFactory = blobIdFactory;
+    }
+
+    public Mono<Pair<AttachmentMetadata, BlobId>> getAttachment(AttachmentId 
attachmentId) {
+        return postgresExecutor.executeRow(dslContext -> 
Mono.from(dslContext.selectFrom(PostgresAttachmentTable.TABLE_NAME)

Review Comment:
   Just a tiny detail but I think we can select listed columns except the `ID` 
column here to save the network overhead.



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