From 47511a690373f474a424c220db4942bee2ca28f0 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 8 May 2024 12:17:08 +0200 Subject: [PATCH] PERF Use cache for loaded users/contact on project list --- htdocs/langs/en_US/projects.lang | 4 +- htdocs/projet/list.php | 100 ++++++++++++++++++------------- 2 files changed, 59 insertions(+), 45 deletions(-) diff --git a/htdocs/langs/en_US/projects.lang b/htdocs/langs/en_US/projects.lang index 63f51008ebe..7997b800e9d 100644 --- a/htdocs/langs/en_US/projects.lang +++ b/htdocs/langs/en_US/projects.lang @@ -204,8 +204,8 @@ InputPerWeek=Input per week InputPerMonth=Input per month InputDetail=Input detail TimeAlreadyRecorded=This is time spent already recorded for this task/day and user %s -ProjectsWithThisUserAsContact=Projects with this user as contact -ProjectsWithThisContact=Projects with this third-party contact +ProjectsWithThisUserAsContact=Projects assigned to this user +ProjectsWithThisContact=Projects assigned to this third-party contact TasksWithThisUserAsContact=Tasks assigned to this user ResourceNotAssignedToProject=Not assigned to project ResourceNotAssignedToTheTask=Not assigned to the task diff --git a/htdocs/projet/list.php b/htdocs/projet/list.php index 9a33d6089a8..7757c340418 100644 --- a/htdocs/projet/list.php +++ b/htdocs/projet/list.php @@ -1135,16 +1135,6 @@ if (isModEnabled('category') && $user->hasRight('categorie', 'lire')) { if (getDolGlobalString('MAIN_SEARCH_CATEGORY_CUSTOMER_ON_PROJECT_LIST') && isModEnabled("category") && $user->hasRight('categorie', 'lire')) { $formcategory = new FormCategory($db); $moreforfilter .= $formcategory->getFilterBox(Categorie::TYPE_CUSTOMER, $searchCategoryCustomerList, 'minwidth300', $searchCategoryCustomerList ? $searchCategoryCustomerList : 0); - /*$moreforfilter .= '
'; - $tmptitle = $langs->transnoentities('CustomersProspectsCategoriesShort'); - $moreforfilter .= img_picto($tmptitle, 'category', 'class="pictofixedwidth"'); - $categoriesArr = $form->select_all_categories(Categorie::TYPE_CUSTOMER, '', '', 64, 0, 3); - $categoriesArr[-2] = '- '.$langs->trans('NotCategorized').' -'; - $moreforfilter .= Form::multiselectarray('search_category_customer_list', $categoriesArr, $searchCategoryCustomerList, 0, 0, 'minwidth300im minwidth300 widthcentpercentminusx', 0, 0, '', 'category', $tmptitle); - $moreforfilter .= ' '; - $moreforfilter .= $form->textwithpicto('', $langs->trans('UseOrOperatorForCategories') . ' : ' . $tmptitle, 1, 'help', '', 0, 2, 'tooltip_cat_cus'); // Tooltip on click - $moreforfilter .= '
'; - */ } if (getDolGlobalInt('PROJECT_ENABLE_SUB_PROJECT')) { @@ -1537,6 +1527,20 @@ while ($i < $imaxinloop) { break; // Should not happen } + // Thirdparty + $companystatic->id = $obj->socid; + $companystatic->name = $obj->name; + $companystatic->name_alias = $obj->alias; + $companystatic->client = $obj->client; + $companystatic->code_client = $obj->code_client; + $companystatic->email = $obj->email; + $companystatic->phone = $obj->phone; + $companystatic->address = $obj->address; + $companystatic->zip = $obj->zip; + $companystatic->town = $obj->town; + $companystatic->country_code = $obj->country_code; + + // Project $object->id = $obj->id; $object->ref = $obj->ref; $object->title = $obj->title; @@ -1560,25 +1564,10 @@ while ($i < $imaxinloop) { $object->usage_organize_event = $obj->usage_organize_event; $object->email_msgid = $obj->email_msgid; $object->import_key = $obj->import_key; - + $object->thirdparty = $companystatic; //$userAccess = $object->restrictedProjectArea($user); // disabled, permission on project must be done by the select - // Thirdparty - $companystatic->id = $obj->socid; - $companystatic->name = $obj->name; - $companystatic->name_alias = $obj->alias; - $companystatic->client = $obj->client; - $companystatic->code_client = $obj->code_client; - $companystatic->email = $obj->email; - $companystatic->phone = $obj->phone; - $companystatic->address = $obj->address; - $companystatic->zip = $obj->zip; - $companystatic->town = $obj->town; - $companystatic->country_code = $obj->country_code; - - $object->thirdparty = $companystatic; - $stringassignedusers = ''; if (!empty($arrayfields['c.assigned']['checked'])) { @@ -1590,25 +1579,27 @@ while ($i < $imaxinloop) { foreach ($tab as $contactproject) { //var_dump($contacttask); if ($source == 'internal') { - $c = new User($db); + if (!empty($conf->cache['user'][$contactproject['id']])) { + $c = $conf->cache['user'][$contactproject['id']]; + } else { + $c = new User($db); + $c->fetch($contactproject['id']); + $conf->cache['user'][$contactproject['id']] = $c; + } } else { - $c = new Contact($db); + if (!empty($conf->cache['contact'][$contactproject['id']])) { + $c = $conf->cache['contact'][$contactproject['id']]; + } else { + $c = new Contact($db); + $c->fetch($contactproject['id']); + $conf->cache['contact'][$contactproject['id']] = $c; + } } - $c->fetch($contactproject['id']); - //var_dump($c->photo); - //if (!empty($c->photo)) { if (get_class($c) == 'User') { $stringassignedusers .= $c->getNomUrl(-2, '', 0, 0, 24, 1, '', 'valignmiddle'.($ifisrt ? '' : ' notfirst')); } else { $stringassignedusers .= $c->getNomUrl(-2, '', 0, '', -1, 0, 'valignmiddle'.($ifisrt ? '' : ' notfirst')); } - /*} else { - if (get_class($c) == 'User') { - $stringassignedusers .= $c->getNomUrl(2, '', 0, 0, 24, 1, '', 'valignmiddle'.($ifisrt ? '' : ' notfirst')); - } else { - $stringassignedusers .= $c->getNomUrl(2, '', 0, '', -1, 0, 'valignmiddle'.($ifisrt ? '' : ' notfirst')); - } - }*/ $ifisrt = 0; } } @@ -1620,12 +1611,17 @@ while ($i < $imaxinloop) { print ''; print '
'; } - - $selected = in_array($object->id, $arrayofselected); + // Output Kanban + $selected = -1; + if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined + $selected = 0; + if (in_array($object->id, $arrayofselected)) { + $selected = 1; + } + } $arrayofdata = array('assignedusers' => $stringassignedusers, 'thirdparty' => $companystatic, 'selected' => $selected); print $object->getKanbanView('', $arrayofdata); - if ($i == ($imaxinloop - 1)) { print '
'; print ''; @@ -1979,8 +1975,6 @@ while ($i < $imaxinloop) { print ''; if ($userstatic->id) { print $userstatic->getNomUrl(-1); - } else { - print ' '; } print "\n"; if (!$i) { @@ -2081,6 +2075,26 @@ print ''."\n"; print ''."\n"; +if (in_array('builddoc', array_keys($arrayofmassactions)) && ($nbtotalofrecords === '' || $nbtotalofrecords)) { + $hidegeneratedfilelistifempty = 1; + if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) { + $hidegeneratedfilelistifempty = 0; + } + + require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php'; + $formfile = new FormFile($db); + + // Show list of available documents + $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder; + $urlsource .= str_replace('&', '&', $param); + + $filedir = $diroutputmassaction; + $genallowed = $permissiontoread; + $delallowed = $permissiontoadd; + + print $formfile->showdocuments('massfilesarea_'.$object->module, '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty); +} + // End of page llxFooter(); $db->close();