Skip to content
Snippets Groups Projects
Commit 000efea8 authored by Joseph AKEL's avatar Joseph AKEL
Browse files

Merge branch 'fix/31828/2301.1.x' into '2301.1.x'

[31828] La recherche de circuits dans le périmètre de l'utilisateur est très lente ou n'aboutit pas

See merge request maarch/MaarchParapheur!285
parents 14fad48a d89ef36c
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