mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-08 19:21:40 +09:00
Update category document count using +1/-1 diff instead of running COUNT(*) query every time
This commit is contained in:
parent
85532fa502
commit
7df5a84f11
2 changed files with 19 additions and 9 deletions
|
|
@ -840,7 +840,7 @@ class DocumentController extends Document
|
||||||
// Update the category if the category_srl exists.
|
// Update the category if the category_srl exists.
|
||||||
if($obj->category_srl)
|
if($obj->category_srl)
|
||||||
{
|
{
|
||||||
$this->updateCategoryCount($obj->module_srl, $obj->category_srl);
|
$this->updateCategoryCount($obj->module_srl, $obj->category_srl, '+1');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Call a trigger (after)
|
// Call a trigger (after)
|
||||||
|
|
@ -1192,11 +1192,11 @@ class DocumentController extends Document
|
||||||
{
|
{
|
||||||
if($source_obj->get('category_srl') != $obj->category_srl)
|
if($source_obj->get('category_srl') != $obj->category_srl)
|
||||||
{
|
{
|
||||||
$this->updateCategoryCount($obj->module_srl, $source_obj->get('category_srl'));
|
$this->updateCategoryCount($obj->module_srl, $source_obj->get('category_srl'), '-1');
|
||||||
}
|
}
|
||||||
if($obj->category_srl)
|
if($obj->category_srl)
|
||||||
{
|
{
|
||||||
$this->updateCategoryCount($obj->module_srl, $obj->category_srl);
|
$this->updateCategoryCount($obj->module_srl, $obj->category_srl, '+1');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1343,7 +1343,10 @@ class DocumentController extends Document
|
||||||
$this->deleteDocumentAliasByDocument($document_srl);
|
$this->deleteDocumentAliasByDocument($document_srl);
|
||||||
$this->deleteDocumentHistory(null, $document_srl, null);
|
$this->deleteDocumentHistory(null, $document_srl, null);
|
||||||
// Update category information if the category_srl exists.
|
// Update category information if the category_srl exists.
|
||||||
if($oDocument->get('category_srl')) $this->updateCategoryCount($oDocument->get('module_srl'),$oDocument->get('category_srl'));
|
if($oDocument->get('category_srl'))
|
||||||
|
{
|
||||||
|
$this->updateCategoryCount($oDocument->get('module_srl'),$oDocument->get('category_srl'), '-1');
|
||||||
|
}
|
||||||
// Delete a declared list
|
// Delete a declared list
|
||||||
executeQuery('document.deleteDeclared', $args);
|
executeQuery('document.deleteDeclared', $args);
|
||||||
// Delete extra variable
|
// Delete extra variable
|
||||||
|
|
@ -1475,7 +1478,7 @@ class DocumentController extends Document
|
||||||
// update category
|
// update category
|
||||||
if ($oDocument->get('category_srl'))
|
if ($oDocument->get('category_srl'))
|
||||||
{
|
{
|
||||||
$this->updateCategoryCount($oDocument->get('module_srl'), $oDocument->get('category_srl'));
|
$this->updateCategoryCount($oDocument->get('module_srl'), $oDocument->get('category_srl'), '-1');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the attachment to be invalid state
|
// Set the attachment to be invalid state
|
||||||
|
|
@ -2343,20 +2346,26 @@ class DocumentController extends Document
|
||||||
* Update document_count in the category.
|
* Update document_count in the category.
|
||||||
* @param int $module_srl
|
* @param int $module_srl
|
||||||
* @param int $category_srl
|
* @param int $category_srl
|
||||||
* @param int $document_count
|
* @param int|string $document_count
|
||||||
* @return object
|
* @return object
|
||||||
*/
|
*/
|
||||||
function updateCategoryCount($module_srl, $category_srl, $document_count = 0)
|
function updateCategoryCount($module_srl, $category_srl, $document_count = 0)
|
||||||
{
|
{
|
||||||
// Create a document model object
|
// Create a document model object
|
||||||
if(!$document_count)
|
if (preg_match('/^[+-]/', (string)$document_count))
|
||||||
{
|
{
|
||||||
$document_count = DocumentModel::getCategoryDocumentCount($module_srl,$category_srl);
|
$document_count = intval($document_count, 10);
|
||||||
|
$mode = 'document_count_diff';
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$document_count = $document_count ?: DocumentModel::getCategoryDocumentCount($module_srl,$category_srl);
|
||||||
|
$mode = 'document_count';
|
||||||
}
|
}
|
||||||
|
|
||||||
$args = new stdClass;
|
$args = new stdClass;
|
||||||
$args->category_srl = $category_srl;
|
$args->category_srl = $category_srl;
|
||||||
$args->document_count = $document_count;
|
$args->{$mode} = $document_count;
|
||||||
$output = executeQuery('document.updateCategoryCount', $args);
|
$output = executeQuery('document.updateCategoryCount', $args);
|
||||||
if($output->toBool()) $this->makeCategoryFile($module_srl);
|
if($output->toBool()) $this->makeCategoryFile($module_srl);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@
|
||||||
</tables>
|
</tables>
|
||||||
<columns>
|
<columns>
|
||||||
<column name="document_count" var="document_count" />
|
<column name="document_count" var="document_count" />
|
||||||
|
<column name="document_count" var="document_count_diff" operation="plus" />
|
||||||
<column name="last_update" var="last_update" default="curdate()" />
|
<column name="last_update" var="last_update" default="curdate()" />
|
||||||
</columns>
|
</columns>
|
||||||
<conditions>
|
<conditions>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue