Skip to content
Snippets Groups Projects
Commit d89ef36c authored by nicoutur's avatar nicoutur
Browse files

FIX #31828 TIME 2:20 Optimize search request with visibility restriction

parent 14fad48a
No related branches found
No related tags found
No related merge requests found
......@@ -42,19 +42,21 @@ class SearchController
$baseRestriction = '';
$baseData = [];
if (!$hasFullRights) {
$baseRestriction = 'id IN (
SELECT DISTINCT ws1.main_document_id
$baseRestriction = 'EXISTS (
SELECT 1
FROM workflows ws1
WHERE typist = ?
OR (ws1.process_date IS NOT NULL AND ws1.user_id = ?)
OR (
ws1.user_id IN (
SELECT (SELECT ?::int) UNION (SELECT id FROM users WHERE substitute = ?)
)
AND ws1."order" = (
SELECT min(ws2."order") FROM workflows ws2 WHERE ws2.process_date IS NULL AND ws2.main_document_id = ws1.main_document_id
)
)
LEFT JOIN users u ON ws1.user_id = u.id AND u.substitute = ?
LEFT JOIN (
SELECT main_document_id, MIN("order") AS min_order
FROM workflows
WHERE process_date IS NULL
GROUP BY main_document_id
) mo ON ws1.main_document_id = mo.main_document_id
WHERE ws1.main_document_id = main_documents.id
AND (main_documents.typist = ?
OR (ws1.process_date IS NOT NULL AND ws1.user_id = ?)
OR (ws1.user_id = ? OR u.id IS NOT NULL)
AND ws1."order" = mo.min_order)
)';
$baseData = [$GLOBALS['id'], $GLOBALS['id'], $GLOBALS['id'], $GLOBALS['id']];
}
......@@ -120,7 +122,7 @@ class SearchController
$where[] = 'id = ?';
$data[] = $body['documentId'];
}
if (Validator::arrayType()->each(Validator::in(['softDeleted', 'hardDeleted']))->notEmpty()->validate($body['documentState'] ?? null)) {
$docStatesForQuery = [];
if (in_array('softDeleted', $body['documentState'])) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment