Fix performance problems Enter new time spent duration becoma < 1s
instead of 30s with 5000 tasks.
This commit is contained in:
parent
298c55b3ed
commit
d8d938e82c
@ -579,7 +579,7 @@ class FormOther
|
||||
{
|
||||
print " ";
|
||||
}
|
||||
print $lines[$i]->ref.'-'.$lines[$i]->label."</option>\n";
|
||||
print $lines[$i]->ref.' '.$lines[$i]->label."</option>\n";
|
||||
$inc++;
|
||||
}
|
||||
|
||||
|
||||
@ -526,7 +526,7 @@ function projectLinesa(&$inc, $parent, &$lines, &$level, $var, $showproject, &$t
|
||||
* Output a task line into a pertime intput mode
|
||||
*
|
||||
* @param string $inc Line number (start to 0, then increased by recursive call)
|
||||
* @param string $parent Id of parent project to show (0 to show all)
|
||||
* @param string $parent Id of parent task to show (0 to show all)
|
||||
* @param Task[] $lines Array of lines
|
||||
* @param int $level Level (start to 0, then increased/decrease by recursive call)
|
||||
* @param string $projectsrole Array of roles user has on project
|
||||
@ -534,40 +534,61 @@ function projectLinesa(&$inc, $parent, &$lines, &$level, $var, $showproject, &$t
|
||||
* @param string $mine Show only task lines I am assigned to
|
||||
* @param int $restricteditformytask 0=No restriction, 1=Enable add time only if task is a task i am affected to
|
||||
* @param int $preselectedday Preselected day
|
||||
* @param boolean $var Var for css of lines
|
||||
* @return $inc
|
||||
*/
|
||||
function projectLinesPerDay(&$inc, $parent, $lines, &$level, &$projectsrole, &$tasksrole, $mine, $restricteditformytask=1, $preselectedday='')
|
||||
function projectLinesPerDay(&$inc, $parent, $lines, &$level, &$projectsrole, &$tasksrole, $mine, $restricteditformytask=1, $preselectedday='', $var=false)
|
||||
{
|
||||
global $db, $user, $bc, $langs;
|
||||
global $form, $formother, $projectstatic, $taskstatic;
|
||||
|
||||
$lastprojectid=0;
|
||||
|
||||
$var=true;
|
||||
|
||||
$workloadloadforid=array();
|
||||
$lineswithoutlevel0=array();
|
||||
|
||||
$numlines=count($lines);
|
||||
|
||||
// Create a smaller array with sublevels only to be used later. This increase dramatically performances.
|
||||
if ($parent == 0) // Always and only if at first level
|
||||
{
|
||||
for ($i = 0 ; $i < $numlines ; $i++)
|
||||
{
|
||||
if ($lines[$i]->fk_task_parent) $lineswithoutlevel0[]=$lines[$i];
|
||||
}
|
||||
}
|
||||
|
||||
//dol_syslog('projectLinesPerDay inc='.$inc.' preselectedday='.$preselectedday.' task parent id='.$parent.' level='.$level." count(lines)=".$numlines." count(lineswithoutlevel0)=".count($lineswithoutlevel0));
|
||||
|
||||
for ($i = 0 ; $i < $numlines ; $i++)
|
||||
{
|
||||
if ($parent == 0) $level = 0;
|
||||
|
||||
if ($lines[$i]->fk_parent == $parent)
|
||||
if ($lines[$i]->fk_task_parent == $parent)
|
||||
{
|
||||
// Break on a new project
|
||||
if ($parent == 0 && $lines[$i]->fk_project != $lastprojectid)
|
||||
{
|
||||
$var = !$var;
|
||||
$lastprojectid=$lines[$i]->fk_project;
|
||||
|
||||
if ($preselectedday)
|
||||
{
|
||||
$projectstatic->id = $lines[$i]->fk_project;
|
||||
$projectstatic->loadTimeSpent($preselectedday, 0, $fuser->id); // Load time spent into this->weekWorkLoad and this->weekWorkLoadPerTaks for all day of a week
|
||||
}
|
||||
}
|
||||
|
||||
// If we want all or we have a role on task, we show it
|
||||
if (empty($mine) || ! empty($tasksrole[$lines[$i]->id]))
|
||||
{
|
||||
//dol_syslog("projectLinesPerWeek Found line ".$i.", a qualified task (i have role or want to show all tasks) with id=".$lines[$i]->id." project id=".$lines[$i]->fk_project);
|
||||
|
||||
// Break on a new project
|
||||
if ($parent == 0 && $lines[$i]->fk_project != $lastprojectid)
|
||||
{
|
||||
$lastprojectid=$lines[$i]->fk_project;
|
||||
if ($preselectedday)
|
||||
{
|
||||
$projectstatic->id = $lines[$i]->fk_project;
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($workloadforid[$projectstatic->id]))
|
||||
{
|
||||
if ($preselectedday)
|
||||
{
|
||||
$projectstatic->loadTimeSpent($preselectedday, 0, $fuser->id); // Load time spent from table projet_task_time for the project into this->weekWorkLoad and this->weekWorkLoadPerTask for all days of a week
|
||||
$workloadforid[$projectstatic->id]=1;
|
||||
}
|
||||
}
|
||||
|
||||
$projectstatic->id=$lines[$i]->fk_project;
|
||||
$projectstatic->ref=$lines[$i]->projectref;
|
||||
$projectstatic->title=$lines[$i]->projectlabel;
|
||||
@ -681,7 +702,11 @@ function projectLinesPerDay(&$inc, $parent, $lines, &$level, &$projectsrole, &$t
|
||||
|
||||
$inc++;
|
||||
$level++;
|
||||
if ($lines[$i]->id) projectLinesPerDay($inc, $lines[$i]->id, $lines, $level, $projectsrole, $tasksrole, $mine, $restricteditformytask, $preselectedday);
|
||||
if ($lines[$i]->id > 0)
|
||||
{
|
||||
if ($parent == 0) projectLinesPerDay($inc, $lines[$i]->id, $lineswithoutlevel0, $level, $projectsrole, $tasksrole, $mine, $restricteditformytask, $preselectedday, $var);
|
||||
else projectLinesPerDay($inc, $lines[$i]->id, $lines, $level, $projectsrole, $tasksrole, $mine, $restricteditformytask, $preselectedday, $var);
|
||||
}
|
||||
$level--;
|
||||
}
|
||||
else
|
||||
@ -698,49 +723,60 @@ function projectLinesPerDay(&$inc, $parent, $lines, &$level, &$projectsrole, &$t
|
||||
/**
|
||||
* Output a task line into a perday intput mode
|
||||
*
|
||||
* @param string $inc Line number (start to 0, then increased by recursive call)
|
||||
* @param string $inc Line output identificator (start to 0, then increased by recursive call)
|
||||
* @param int $firstdaytoshow First day to show
|
||||
* @param User|null $fuser Restrict list to user if defined
|
||||
* @param string $parent Id of parent project to show (0 to show all)
|
||||
* @param string $parent Id of parent task to show (0 to show all)
|
||||
* @param Task[] $lines Array of lines (list of tasks but we will show only if we have a specific role on task)
|
||||
* @param int $level Level (start to 0, then increased/decrease by recursive call)
|
||||
* @param string $projectsrole Array of roles user has on project
|
||||
* @param string $tasksrole Array of roles user has on task
|
||||
* @param string $mine Show only task lines I am assigned to
|
||||
* @param int $restricteditformytask 0=No restriction, 1=Enable add time only if task is a task i am affected to
|
||||
* @param boolean $var Var for css of lines
|
||||
* @return $inc
|
||||
*/
|
||||
function projectLinesPerWeek(&$inc, $firstdaytoshow, $fuser, $parent, $lines, &$level, &$projectsrole, &$tasksrole, $mine, $restricteditformytask=1)
|
||||
function projectLinesPerWeek(&$inc, $firstdaytoshow, $fuser, $parent, $lines, &$level, &$projectsrole, &$tasksrole, $mine, $restricteditformytask=1, $var=false)
|
||||
{
|
||||
global $db, $user, $bc, $langs;
|
||||
global $form, $formother, $projectstatic, $taskstatic;
|
||||
|
||||
|
||||
$var=true;
|
||||
|
||||
$numlines=count($lines);
|
||||
|
||||
$lastprojectid=0;
|
||||
$workloadloadforid=array();
|
||||
$lineswithoutlevel0=array();
|
||||
|
||||
// Create a smaller array with sublevels only to be used later. This increase dramatically performances.
|
||||
if ($parent == 0) // Always and only if at first level
|
||||
{
|
||||
for ($i = 0 ; $i < $numlines ; $i++)
|
||||
{
|
||||
if ($lines[$i]->fk_task_parent) $lineswithoutlevel0[]=$lines[$i];
|
||||
}
|
||||
}
|
||||
|
||||
//dol_syslog('projectLinesPerWeek inc='.$inc.' firstdaytoshow='.$firstdaytoshow.' task parent id='.$parent.' level='.$level." count(lines)=".$numlines." count(lineswithoutlevel0)=".count($lineswithoutlevel0));
|
||||
|
||||
for ($i = 0 ; $i < $numlines ; $i++)
|
||||
{
|
||||
if ($parent == 0) $level = 0;
|
||||
|
||||
if ($lines[$i]->fk_parent == $parent)
|
||||
|
||||
if ($lines[$i]->fk_task_parent == $parent)
|
||||
{
|
||||
// Break on a new project
|
||||
if ($parent == 0 && $lines[$i]->fk_project != $lastprojectid)
|
||||
{
|
||||
$var = !$var;
|
||||
$lastprojectid=$lines[$i]->fk_project;
|
||||
|
||||
$projectstatic->id = $lines[$i]->fk_project;
|
||||
}
|
||||
|
||||
// If we want all or we have a role on task, we show it
|
||||
if (empty($mine) || ! empty($tasksrole[$lines[$i]->id]))
|
||||
{
|
||||
//dol_syslog("projectLinesPerWeek Found line ".$i.", a qualified task (i have role or want to show all tasks) with id=".$lines[$i]->id." project id=".$lines[$i]->fk_project);
|
||||
|
||||
// Break on a new project
|
||||
if ($parent == 0 && $lines[$i]->fk_project != $lastprojectid)
|
||||
{
|
||||
//$var = ! $var;
|
||||
$lastprojectid=$lines[$i]->fk_project;
|
||||
$projectstatic->id = $lines[$i]->fk_project;
|
||||
}
|
||||
|
||||
if (empty($workloadforid[$projectstatic->id]))
|
||||
{
|
||||
$projectstatic->loadTimeSpent($firstdaytoshow, 0, $fuser->id); // Load time spent from table projet_task_time for the project into this->weekWorkLoad and this->weekWorkLoadPerTask for all days of a week
|
||||
@ -750,7 +786,7 @@ function projectLinesPerWeek(&$inc, $firstdaytoshow, $fuser, $parent, $lines, &$
|
||||
print "<tr ".$bc[$var].">\n";
|
||||
|
||||
// Project
|
||||
print '<td class="nowrap">';
|
||||
print '<td class="nowrap">'.$var;
|
||||
$projectstatic->id=$lines[$i]->fk_project;
|
||||
$projectstatic->ref=$lines[$i]->projectref;
|
||||
$projectstatic->title=$lines[$i]->projectlabel;
|
||||
@ -826,7 +862,7 @@ function projectLinesPerWeek(&$inc, $firstdaytoshow, $fuser, $parent, $lines, &$
|
||||
}
|
||||
|
||||
//var_dump($projectstatic->weekWorkLoadPerTask);
|
||||
|
||||
|
||||
// Fields to show current time
|
||||
$tableCell=''; $modeinput='hours';
|
||||
for ($idw = 0; $idw < 7; $idw++)
|
||||
@ -852,7 +888,8 @@ function projectLinesPerWeek(&$inc, $firstdaytoshow, $fuser, $parent, $lines, &$
|
||||
$tableCell.='</td>';
|
||||
print $tableCell;
|
||||
}
|
||||
|
||||
dol_syslog("yyy");
|
||||
|
||||
print '<td align="right">';
|
||||
if ((! $lines[$i]->public) && $disabledproject) print $form->textwithpicto('',$langs->trans("YouAreNotContactOfProject"));
|
||||
else if ($disabledtask) print $form->textwithpicto('',$langs->trans("TaskIsNotAffectedToYou"));
|
||||
@ -861,9 +898,14 @@ function projectLinesPerWeek(&$inc, $firstdaytoshow, $fuser, $parent, $lines, &$
|
||||
print "</tr>\n";
|
||||
}
|
||||
|
||||
// Call to show task with a lower level (task under the current task)
|
||||
$inc++;
|
||||
$level++;
|
||||
if ($lines[$i]->id) projectLinesPerWeek($inc, $firstdaytoshow, $fuser, $lines[$i]->id, $lines, $level, $projectsrole, $tasksrole, $mine, $restricteditformytask);
|
||||
if ($lines[$i]->id > 0)
|
||||
{
|
||||
if ($parent == 0) projectLinesPerWeek($inc, $firstdaytoshow, $fuser, $lines[$i]->id, $lineswithoutlevel0, $level, $projectsrole, $tasksrole, $mine, $restricteditformytask, $var);
|
||||
else projectLinesPerWeek($inc, $firstdaytoshow, $fuser, $lines[$i]->id, $lines, $level, $projectsrole, $tasksrole, $mine, $restricteditformytask, $var);
|
||||
}
|
||||
$level--;
|
||||
}
|
||||
else
|
||||
|
||||
Loading…
Reference in New Issue
Block a user