fix: trim duplicate search results for external share

Signed-off-by: Maksim Sukharev <antreesy.web@gmail.com>
This commit is contained in:
niv 2026-05-19 18:04:31 +02:00 committed by backportbot[bot]
parent 739b43a003
commit d29c43d91e

View file

@ -94,13 +94,17 @@ class Search implements ISearch {
$emailType = new SearchResultType('emails');
$remoteType = new SearchResultType('remotes');
if (!isset($allResults[$remoteType->getLabel()])
|| !isset($allResults[$emailType->getLabel()])) {
$emailLabel = $emailType->getLabel();
$emailEntries = array_merge(
$allResults['exact'][$emailLabel] ?? [],
$allResults[$emailLabel] ?? []
);
if ($emailEntries === []) {
return;
}
$mailIdMap = [];
foreach ($allResults[$emailType->getLabel()] as $mailRow) {
foreach ($emailEntries as $mailRow) {
// sure, array_reduce looks nicer, but foreach needs less resources and is faster
if (!isset($mailRow['uuid'])) {
continue;
@ -116,5 +120,17 @@ class Search implements ISearch {
$searchResult->removeCollaboratorResult($emailType, $mailIdMap[$resultRow['uuid']]);
}
}
$lookupType = new SearchResultType('lookup');
if (isset($allResults[$lookupType->getLabel()])) {
foreach ($allResults[$lookupType->getLabel()] as $resultRow) {
$userid = $resultRow['extra']['userid']['value'] ?? null;
if ($userid === null) {
continue;
}
if (isset($mailIdMap[$userid])) {
$searchResult->removeCollaboratorResult($emailType, $mailIdMap[$userid]);
}
}
}
}
}