Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@Arsnael
Copy link
Contributor

@Arsnael Arsnael commented Aug 29, 2025

Still left Cassandra and Postgresql implem finalizing

Copy link
Member

@quantranhong1999 quantranhong1999 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Read it. This seems to be going in the right direction to me.

public Flux<MessageId> listMailboxContentSortedBySentAt(MailboxId mailboxId, Limit limit, boolean collapseThreads) {
Preconditions.checkArgument(!limit.isUnlimited(), "Limit should be defined");

Limit limitFetch = defineLimitFetch(limit, collapseThreads);
Copy link
Contributor Author

@Arsnael Arsnael Sep 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cassandra is defo trickier :)

I'm not sure here...
I've been thinking quite a lot, this is a proposition among others. I feel like looping on cassandra requests until we meet the limit for collapseThreads would complexify greatly the code and for not such a great gain (more costly in perf too).

I thought:

  • or we do like some requests that need to be post-sorted, just fetch all records, then collapsing threads and take the limit
  • or we fetch an upper limit (here 3 times the limit defined) and we collapse threads and then take up to the limit. We accept that maybe sometimes we could have a bit less than the limit (hopefully rare enough) but it should stay balanced in terms of perf and keep the code relatively simple.

I tried to look at paging too but that would complexify a lot the code as well I believe (like looping).

Well brain storming welcomed honestly

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can get a try to the cassandra implem but yes we would need some extra work for Cassandra.

However can we focus on the short term on SaaS related topis?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok...

@Arsnael Arsnael force-pushed the jmap-thread-collapse branch from 148c930 to 5bebc68 Compare November 5, 2025 03:19
@Arsnael
Copy link
Contributor Author

Arsnael commented Nov 6, 2025

Cassandra implem passes the tests... Just needs a good refactoring to make something really clean (cause quite dirty atm) and still left the pg implem.

Comment on lines +245 to +258
if (collapseThreads) {
return baseEntries.collectList()
.flatMapMany(results -> {
List<EmailEntry> distinctByThreadId = distinctByThreadId(results);
boolean hasEnoughResults = distinctByThreadId.size() >= limit.getLimit().get();
boolean isExhaustive = results.size() < backendFetchLimit.getLimit().get();
if (hasEnoughResults || isExhaustive) {
return Flux.fromIterable(distinctByThreadId)
.take(limit.getLimit().get())
.map(EmailEntry::getMessageId);
}
Limit newBackendFetchLimit = Limit.from(backendFetchLimit.getLimit().get() * COLLAPSE_THREADS_LIMIT_MULTIPLIER);
return listMailboxContentSortedBySentAtWithBackendLimit(mailboxId, limit, collapseThreads, newBackendFetchLimit);
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need an abstraction not to repeat this piece of code.
Refactorig?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants