Skip to content
Snippets Groups Projects
Verified Commit 04da996c authored by Damien's avatar Damien
Browse files

FEAT #10551 TIME 0:45 search ilike + optimize count

parent f58b8273
No related branches found
No related tags found
No related merge requests found
...@@ -70,7 +70,7 @@ class DocumentController ...@@ -70,7 +70,7 @@ class DocumentController
$where = ['id in (?)']; $where = ['id in (?)'];
$data = [$documentIds]; $data = [$documentIds];
if (!empty($queryParams['search'])) { if (!empty($queryParams['search'])) {
$where[] = '(title like ? OR reference like ?)'; $where[] = '(title ilike ? OR reference ilike ?)';
$data[] = "%{$queryParams['search']}%"; $data[] = "%{$queryParams['search']}%";
$data[] = "%{$queryParams['search']}%"; $data[] = "%{$queryParams['search']}%";
} }
...@@ -106,28 +106,14 @@ class DocumentController ...@@ -106,28 +106,14 @@ class DocumentController
} }
$adr = AdrModel::getDocumentsAdr([ $adr = AdrModel::getDocumentsAdr([
'select' => ['path', 'filename'], 'select' => ['count(1)'],
'where' => ['main_document_id = ?', 'type = ?'], 'where' => ['main_document_id = ?', 'type != ?'],
'data' => [$args['id'], 'DOC'] 'data' => [$args['id'], 'DOC']
]); ]);
if (empty($adr)) { if (empty($adr[0]['count'])) {
return $response->withStatus(400)->withJson(['errors' => 'Document does not exist']); return $response->withStatus(400)->withJson(['errors' => 'Document thumbnails do not exist']);
}
$docserver = DocserverModel::getByType(['type' => 'DOC', 'select' => ['path']]);
if (empty($docserver['path']) || !is_dir($docserver['path'])) {
return $response->withStatus(400)->withJson(['errors' => 'Docserver does not exist']);
} }
$pathToDocument = $docserver['path'] . $adr[0]['path'] . $adr[0]['filename'];
if (!is_file($pathToDocument) || !is_readable($pathToDocument)) {
return $response->withStatus(400)->withJson(['errors' => 'Document not found on docserver or not readable']);
}
$img = new \Imagick();
$img->pingImage($pathToDocument);
$pagesCount = $img->getNumberImages();
$formattedDocument = [ $formattedDocument = [
'id' => $document['id'], 'id' => $document['id'],
'title' => $document['title'], 'title' => $document['title'],
...@@ -136,7 +122,7 @@ class DocumentController ...@@ -136,7 +122,7 @@ class DocumentController
'sender' => $document['sender'], 'sender' => $document['sender'],
'creationDate' => $document['creation_date'], 'creationDate' => $document['creation_date'],
'modificationDate' => $document['modification_date'], 'modificationDate' => $document['modification_date'],
'pages' => $pagesCount 'pages' => $adr[0]['count']
]; ];
if (!empty($document['deadline'])) { if (!empty($document['deadline'])) {
$date = new \DateTime($document['deadline']); $date = new \DateTime($document['deadline']);
...@@ -179,17 +165,12 @@ class DocumentController ...@@ -179,17 +165,12 @@ class DocumentController
foreach ($attachments as $attachment) { foreach ($attachments as $attachment) {
$pagesCount = 0; $pagesCount = 0;
$adr = AdrModel::getAttachmentsAdr([ $adr = AdrModel::getAttachmentsAdr([
'select' => ['path', 'filename'], 'select' => ['count(1)'],
'where' => ['attachment_id = ?', 'type = ?'], 'where' => ['attachment_id = ?', 'type != ?'],
'data' => [$attachment['id'], 'ATTACH'] 'data' => [$attachment['id'], 'ATTACH']
]); ]);
$docserver = DocserverModel::getByType(['type' => 'ATTACH', 'select' => ['path']]); if (!empty($adr[0]['count'])) {
$pagesCount = $adr[0]['count'];
$pathToDocument = $docserver['path'] . $adr[0]['path'] . $adr[0]['filename'];
if (is_file($pathToDocument) && is_readable($pathToDocument)) {
$img = new \Imagick();
$img->pingImage($pathToDocument);
$pagesCount = $img->getNumberImages();
} }
$formattedDocument['attachments'][] = [ $formattedDocument['attachments'][] = [
......
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