james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <server-...@james.apache.org>
Subject [jira] [Commented] (JAMES-2298) FileMailQueue do not support remove
Date Tue, 06 Nov 2018 02:28:00 GMT

    [ https://issues.apache.org/jira/browse/JAMES-2298?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16676049#comment-16676049
] 

ASF GitHub Bot commented on JAMES-2298:
---------------------------------------

Github user chibenwa commented on a diff in the pull request:

    https://github.com/apache/james-project/pull/129#discussion_r230982059
  
    --- Diff: server/queue/queue-file/src/main/java/org/apache/james/queue/file/FileMailQueue.java
---
    @@ -390,26 +410,46 @@ public long clear() throws MailQueueException {
             return count;
         }
     
    -    /**
    -     * TODO: implement me
    -     */
         @Override
         public long remove(Type type, String value) throws MailQueueException {
    -        switch (type) {
    -            case Name:
    -                FileItem item = keyMappings.remove(value);
    -                if (item != null) {
    -                    item.delete();
    -                    return 1;
    -                } else {
    -                    return 0;
    -                }
    +        try (IndexReader indexReader = IndexReader.open(indexWriter, true)) {
    +            int maxCount = Math.max(1, indexReader.maxDoc());
    +            IndexSearcher searcher = new IndexSearcher(indexReader);
    +            MutableLong count = new MutableLong();
    +            Term term;
    +            Query query;
    +
    +            switch (type) {
    +                case Name:
    +                case Sender:
    +                case Recipient:
    +                    term = new Term(type.name(), value);
    +                    query = new TermQuery(term);
    +                    break;
    +                default:
    +                    throw new MailQueueException("Not supported yet");
    +            }
     
    -            default:
    -                break;
    +            Optional.ofNullable(searcher.search(query, maxCount).scoreDocs)
    +                    .filter(hits -> hits.length > 0)
    +                    .map(Stream::of)
    +                    .ifPresent(scoreDocStream -> scoreDocStream
    +                            .mapToInt(scoreDoc -> scoreDoc.doc)
    +                            .forEach(id -> Optional.ofNullable(Throwing.supplier(()
-> searcher.doc(id, FIELDS_TO_LOAD)).get())
    +                                    .map(doc -> doc.get(FILE_PATH_KEY))
    +                                    .map(keyMappings::remove)
    +                                    .ifPresent(fileItem -> {
    +                                        Throwing.runnable(fileItem::delete).run();
    +                                        Throwing.<Query>consumer(indexWriter::deleteDocuments).accept(query);
    +
    +                                        count.increment();
    +                                    })
    +                    ));
    --- End diff --
    
    Sorry but this chunk of code is a bit too complex....
    
    Here is what I propose:
    
     - Clearly affect the  `IntStream` of ID to remove to a variable `idToBeRemoved`
     - Use the `.peek(...)` method for performing all needed deletions, one per line.
     - Then rely on the `count()` method to count return results (getting ride of the MutableLong)



> FileMailQueue do not support remove
> -----------------------------------
>
>                 Key: JAMES-2298
>                 URL: https://issues.apache.org/jira/browse/JAMES-2298
>             Project: James Server
>          Issue Type: Bug
>          Components: Queue
>    Affects Versions: master
>            Reporter: Tellier Benoit
>            Priority: Major
>
> An exception is thrown or the code badly modify the state of the queue



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message