Skip to content

Conversation

st3iny
Copy link
Member

@st3iny st3iny commented Jul 31, 2025

For #10668
Ref #10723 (comment)

Get rid of one SQL query for every call to MessagesController::index() (and other consumers of IMailSearch::findMessages()).

Query the search results (messages) directly instead of querying their ids first by the search filter and then doing another query for the actual messages by their ids.

Query the search results (messages) directly instead of querying their
ids first by the search query and then doing another query for the
actual messages.

Signed-off-by: Richard Steinmetz <richard@steinmetz.cloud>
Comment on lines 801 to 812
public function findIdsByQuery(Mailbox $mailbox, SearchQuery $query, string $sortOrder, ?int $limit, ?array $uids = null): array {
return array_map(
static fn (Message $message) => $message->getId(),
$this->findByQueryWithoutRelatedData(
$mailbox,
$query,
$sortOrder,
$limit,
$uids,
),
);
}
Copy link
Member Author

Choose a reason for hiding this comment

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

Potential drawback: Overfetching

If only the IDs are required, the whole row is fetched without being required.

This method is currently only used in \OCA\Mail\Service\Sync\SyncService::getDatabaseSyncChanges().

Copy link
Member

Choose a reason for hiding this comment

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

Depending on the number of emails shown in the client this will be 20 or more rows to overfetch.

What could we do to prevent this? Duplicate findByQueryWithoutRelatedData (ugly) or pass the columns as argument (even uglier)? 🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

Those are the two options I think.

Copy link
Member Author

@st3iny st3iny Aug 22, 2025

Choose a reason for hiding this comment

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

Or, we factor the body of the method (query logic) out and provide two entry points. This makes sense as the columns to be selected is the only thing changing.

EDIT: Ok, this is not much better than just passing the columns.

Copy link
Member Author

Choose a reason for hiding this comment

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

I pushed the version with the columns-as-argument.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants