Fix for performance troubles

This commit is contained in:
Laurent Destailleur 2021-05-03 18:49:37 +02:00
parent 28b1d83ae9
commit 03e8f2aee1
3 changed files with 13 additions and 9 deletions

View File

@ -301,7 +301,7 @@ class BookKeeping extends CommonObject
} }
$sql .= " AND numero_compte = '".$this->db->escape($this->numero_compte)."'"; $sql .= " AND numero_compte = '".$this->db->escape($this->numero_compte)."'";
$sql .= " AND label_operation = '".$this->db->escape($this->label_operation)."'"; $sql .= " AND label_operation = '".$this->db->escape($this->label_operation)."'";
$sql .= " AND entity IN (".getEntity('accountancy').")"; $sql .= " AND entity = ".$conf->entity; // Do not use getEntity for accounting features
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
@ -318,7 +318,7 @@ class BookKeeping extends CommonObject
$sqlnum .= " AND fk_docdet = ".((int) $this->fk_docdet); $sqlnum .= " AND fk_docdet = ".((int) $this->fk_docdet);
} }
$sqlnum .= " AND doc_ref = '".$this->db->escape($this->doc_ref)."'"; // ref of source object $sqlnum .= " AND doc_ref = '".$this->db->escape($this->doc_ref)."'"; // ref of source object
$sqlnum .= " AND entity IN (".getEntity('accountancy').")"; $sqlnum .= " AND entity = ".$conf->entity; // Do not use getEntity for accounting features
dol_syslog(get_class($this).":: create sqlnum=".$sqlnum, LOG_DEBUG); dol_syslog(get_class($this).":: create sqlnum=".$sqlnum, LOG_DEBUG);
$resqlnum = $this->db->query($sqlnum); $resqlnum = $this->db->query($sqlnum);
@ -331,7 +331,7 @@ class BookKeeping extends CommonObject
if (empty($this->piece_num)) { if (empty($this->piece_num)) {
$sqlnum = "SELECT MAX(piece_num)+1 as maxpiecenum"; $sqlnum = "SELECT MAX(piece_num)+1 as maxpiecenum";
$sqlnum .= " FROM ".MAIN_DB_PREFIX.$this->table_element; $sqlnum .= " FROM ".MAIN_DB_PREFIX.$this->table_element;
$sqlnum .= " WHERE entity IN (".getEntity('accountancy').")"; $sqlnum .= " WHERE entity = ".$conf->entity; // Do not use getEntity for accounting features
$resqlnum = $this->db->query($sqlnum); $resqlnum = $this->db->query($sqlnum);
if ($resqlnum) { if ($resqlnum) {

View File

@ -32,11 +32,15 @@
-- Missing in v13 or lower -- Missing in v13 or lower
ALTER TABLE llx_accounting_bookkeeping DROP INDEX idx_accounting_bookkeeping_numero_compte;
ALTER TABLE llx_accounting_bookkeeping DROP INDEX idx_accounting_bookkeeping_code_journal;
ALTER TABLE llx_accounting_bookkeeping ADD INDEX idx_accounting_bookkeeping_fk_docdet (fk_docdet); ALTER TABLE llx_accounting_bookkeeping ADD INDEX idx_accounting_bookkeeping_fk_docdet (fk_docdet);
ALTER TABLE llx_accounting_bookkeeping ADD INDEX idx_accounting_bookkeeping_doc_date (doc_date); ALTER TABLE llx_accounting_bookkeeping ADD INDEX idx_accounting_bookkeeping_doc_date (doc_date);
ALTER TABLE llx_accounting_bookkeeping ADD INDEX idx_accounting_bookkeeping_numero_compte (numero_compte); ALTER TABLE llx_accounting_bookkeeping ADD INDEX idx_accounting_bookkeeping_numero_compte (numero_compte, entity);
ALTER TABLE llx_accounting_bookkeeping ADD INDEX idx_accounting_bookkeeping_code_journal (code_journal); ALTER TABLE llx_accounting_bookkeeping ADD INDEX idx_accounting_bookkeeping_code_journal (code_journal, entity);
ALTER TABLE llx_accounting_bookkeeping ADD INDEX idx_accounting_bookkeeping_piece_num (piece_num);
ALTER TABLE llx_accounting_bookkeeping ADD INDEX idx_accounting_bookkeeping_piece_num (piece_num, entity);
ALTER TABLE llx_recruitment_recruitmentcandidature MODIFY COLUMN email_msgid VARCHAR(175); ALTER TABLE llx_recruitment_recruitmentcandidature MODIFY COLUMN email_msgid VARCHAR(175);

View File

@ -19,9 +19,9 @@
ALTER TABLE llx_accounting_bookkeeping ADD INDEX idx_accounting_bookkeeping_fk_doc (fk_doc); ALTER TABLE llx_accounting_bookkeeping ADD INDEX idx_accounting_bookkeeping_fk_doc (fk_doc);
ALTER TABLE llx_accounting_bookkeeping ADD INDEX idx_accounting_bookkeeping_fk_docdet (fk_docdet); ALTER TABLE llx_accounting_bookkeeping ADD INDEX idx_accounting_bookkeeping_fk_docdet (fk_docdet);
ALTER TABLE llx_accounting_bookkeeping ADD INDEX idx_accounting_bookkeeping_doc_date (doc_date); ALTER TABLE llx_accounting_bookkeeping ADD INDEX idx_accounting_bookkeeping_doc_date (doc_date);
ALTER TABLE llx_accounting_bookkeeping ADD INDEX idx_accounting_bookkeeping_numero_compte (numero_compte); ALTER TABLE llx_accounting_bookkeeping ADD INDEX idx_accounting_bookkeeping_numero_compte (numero_compte, entity);
ALTER TABLE llx_accounting_bookkeeping ADD INDEX idx_accounting_bookkeeping_code_journal (code_journal); ALTER TABLE llx_accounting_bookkeeping ADD INDEX idx_accounting_bookkeeping_code_journal (code_journal, entity);
ALTER TABLE llx_accounting_bookkeeping ADD INDEX idx_accounting_bookkeeping_piece_num (piece_num); ALTER TABLE llx_accounting_bookkeeping ADD INDEX idx_accounting_bookkeeping_piece_num (piece_num, entity);
-- Current unicity is tested by the journalize page on couple (fk_doc, doc_type) -- Current unicity is tested by the journalize page on couple (fk_doc, doc_type)
-- TODO Add a key for unicity (not so easy as fk_doc, doc_type may have several lines for one piece) -- TODO Add a key for unicity (not so easy as fk_doc, doc_type may have several lines for one piece)