optimisation getissue gitea

This commit is contained in:
afornerot 2024-06-14 18:44:30 +02:00
parent a2d1841631
commit 8bc58f6966
4 changed files with 110 additions and 68 deletions

View File

@ -433,7 +433,6 @@ class ScrumController extends AbstractController
]); ]);
} }
public function table($id, Request $request) public function table($id, Request $request)
{ {
$em = $this->getDoctrine()->getManager(); $em = $this->getDoctrine()->getManager();

View File

@ -85,7 +85,7 @@ class ScrumissueController extends AbstractController
// Récupérer l'issue modifiée pour mettre à jour la date de modification gitea // Récupérer l'issue modifiée pour mettre à jour la date de modification gitea
$giteaissue=$this->giteaservice->getIssue($scrumissue->getScrum()->getGiteajson()["owner"]["login"],$scrumissue->getScrum()->getGiteajson()["name"],$scrumissue->getGiteanumber()); $giteaissue=$this->giteaservice->getIssue($scrumissue->getScrum()->getGiteajson()["owner"]["login"],$scrumissue->getScrum()->getGiteajson()["name"],$scrumissue->getGiteanumber());
if(!$giteaissue) return new JsonResponse(['message' => 'No API getIssue'], 403); if(!$giteaissue) return new JsonResponse(['message' => 'No API getIssue'], 403);
$updateissue=new \DateTime($giteaissue->updated_at); $updateissue=new \DateTime(json_decode(json_encode($giteaissue), true)["updated_at"]);
$updateissue->setTimezone(new \DateTimeZone("UTC")); $updateissue->setTimezone(new \DateTimeZone("UTC"));
$lastupdate=$scrumissue->getScrum()->getUpdatedate(); $lastupdate=$scrumissue->getScrum()->getUpdatedate();

View File

@ -13,13 +13,32 @@ class ScrumRepository extends ServiceEntityRepository
{ {
private $session; private $session;
private $firstcolumn; private $firstcolumn;
private $datescrumupdate; private $totalTime;
private $startTime;
private $showTime;
public function __construct(ManagerRegistry $registry,giteaService $giteaservice,SessionInterface $session) public function __construct(ManagerRegistry $registry,giteaService $giteaservice,SessionInterface $session)
{ {
parent::__construct($registry, Scrum::class); parent::__construct($registry, Scrum::class);
$this->giteaservice = $giteaservice; $this->giteaservice = $giteaservice;
$this->session = $session; $this->session = $session;
$this->showTime = false;
}
private function showtime($istart,$title="") {
if($this->showTime) {
if($istart) {
$this->totalTime = microtime(true);
$this->startTime = microtime(true);
}
else {
$endTime = microtime(true);
$executionTime = $endTime - $this->startTime;
$totalTime = $endTime - $this->totalTime;
dump($executionTime." / ".$totalTime." = ".$title);
$this->startTime = microtime(true);
}
}
} }
public function findByUser($user) { public function findByUser($user) {
@ -40,17 +59,30 @@ class ScrumRepository extends ServiceEntityRepository
public function getGitea($scrum,&$giteaassignees,&$giteacolumns,&$giteamilestones,&$giteateams,&$giteaprioritys,&$giteatypes,&$gitealabels, $forcereload=false) { public function getGitea($scrum,&$giteaassignees,&$giteacolumns,&$giteamilestones,&$giteateams,&$giteaprioritys,&$giteatypes,&$gitealabels, $forcereload=false) {
$this->showtime(true);
$lastupdate = $scrum->getUpdatedate();
if(!$lastupdate) $lastupdate = new \DateTime(("19000101"));
$lastupdate->sub(new \DateInterval('PT30M'));
$viewclosed = $this->session->get("viewclosed"); $viewclosed = $this->session->get("viewclosed");
// Récupérer les labels de gitea // Récupérer les labels de gitea
$gitealabels=$this->giteaservice->getLabels($scrum->getGiteajson()["owner"]["login"],$scrum->getGiteajson()["name"]); $gitealabels=$this->giteaservice->getLabels($scrum->getGiteajson()["owner"]["login"],$scrum->getGiteajson()["name"]);
if(!is_array($gitealabels)) die("Probleme de connexion avec gitea veuillez vous <a href='/logout'>reconnecter</a>"); if(!is_array($gitealabels)) die("Probleme de connexion avec gitea veuillez vous <a href='/logout'>reconnecter</a>");
$giteaidlabels=array_column($gitealabels, 'id');
// Récupérer les jalons de gitea
$giteamilestones=$this->giteaservice->getMilestones($scrum->getGiteajson()["owner"]["login"],$scrum->getGiteajson()["name"]);
if(!is_array($giteamilestones)) die("Probleme de connexion avec gitea veuillez vous <a href='/logout'>reconnecter</a>");
$giteaidmilestones=array_column($giteamilestones, 'id');
// Temps d'execution
$this->showtime(false,"Récupération gitealabels & giteamilestones");
// S'assurer que nos colonnes existes toujours // S'assurer que nos colonnes existes toujours
$scrumcolumns=$scrum->getScrumcolumns(); $scrumcolumns=$scrum->getScrumcolumns();
foreach($scrumcolumns as $scrumcolumn) { foreach($scrumcolumns as $scrumcolumn) {
$gitealabel=$this->giteaservice->getLabel($scrum->getGiteajson()["owner"]["login"],$scrum->getGiteajson()["name"],$scrumcolumn->getGiteaid()); if(!in_array($scrumcolumn->getGiteaid(),$giteaidlabels)) {
if(!$gitealabel) {
$this->_em->remove($scrumcolumn); $this->_em->remove($scrumcolumn);
$this->_em->flush(); $this->_em->flush();
} }
@ -59,8 +91,7 @@ class ScrumRepository extends ServiceEntityRepository
// S'assurer que nos teams existes toujours // S'assurer que nos teams existes toujours
$scrumteams=$scrum->getScrumteams(); $scrumteams=$scrum->getScrumteams();
foreach($scrumteams as $scrumteam) { foreach($scrumteams as $scrumteam) {
$gitealabel=$this->giteaservice->getLabel($scrum->getGiteajson()["owner"]["login"],$scrum->getGiteajson()["name"],$scrumteam->getGiteaid()); if(!in_array($scrumteam->getGiteaid(),$giteaidlabels)) {
if(!$gitealabel) {
$this->_em->remove($scrumteam); $this->_em->remove($scrumteam);
$this->_em->flush(); $this->_em->flush();
} }
@ -69,8 +100,7 @@ class ScrumRepository extends ServiceEntityRepository
// S'assurer que nos prioritys existes toujours // S'assurer que nos prioritys existes toujours
$scrumprioritys=$scrum->getScrumprioritys(); $scrumprioritys=$scrum->getScrumprioritys();
foreach($scrumprioritys as $scrumpriority) { foreach($scrumprioritys as $scrumpriority) {
$gitealabel=$this->giteaservice->getLabel($scrum->getGiteajson()["owner"]["login"],$scrum->getGiteajson()["name"],$scrumpriority->getGiteaid()); if(!in_array($scrumpriority->getGiteaid(),$giteaidlabels)) {
if(!$gitealabel) {
$this->_em->remove($scrumpriority); $this->_em->remove($scrumpriority);
$this->_em->flush(); $this->_em->flush();
} }
@ -79,23 +109,27 @@ class ScrumRepository extends ServiceEntityRepository
// S'assurer que nos types existes toujours // S'assurer que nos types existes toujours
$scrumtypes=$scrum->getScrumtypes(); $scrumtypes=$scrum->getScrumtypes();
foreach($scrumtypes as $scrumtype) { foreach($scrumtypes as $scrumtype) {
$gitealabel=$this->giteaservice->getLabel($scrum->getGiteajson()["owner"]["login"],$scrum->getGiteajson()["name"],$scrumtype->getGiteaid()); if(!in_array($scrumtype->getGiteaid(),$giteaidlabels)) {
if(!$gitealabel) {
$this->_em->remove($scrumtype); $this->_em->remove($scrumtype);
$this->_em->flush(); $this->_em->flush();
} }
} }
// Temps d'execution
$this->showtime(false,"S'assurer que nos labels colonnes teams prioritys types existes toujours");
// S'assurer que nos sprint sont toujours lié à un jalon existant // S'assurer que nos sprint sont toujours lié à un jalon existant
$scrumsprints=$scrum->getScrumsprints(); $scrumsprints=$scrum->getScrumsprints();
foreach($scrumsprints as $scrumsprint) { foreach($scrumsprints as $scrumsprint) {
$giteamilestone=$this->giteaservice->getMilestone($scrum->getGiteajson()["owner"]["login"],$scrum->getGiteajson()["name"],$scrumsprint->getGiteamilestone()); if(!in_array($scrumsprint->getGiteamilestone(),$giteaidmilestones)) {
if(!$giteamilestone) {
$this->_em->remove($scrumsprint); $this->_em->remove($scrumsprint);
$this->_em->flush(); $this->_em->flush();
} }
} }
// Temps d'execution
$this->showtime(false,"S'assurer que nos sprint sont toujours lié à un jalon existant");
// Récupérer le dernier order // Récupérer le dernier order
$last = $this->_em->getRepository('App:Scrumissue')->findOneBy(["scrum"=>$scrum], ['rowid' => 'DESC']); $last = $this->_em->getRepository('App:Scrumissue')->findOneBy(["scrum"=>$scrum], ['rowid' => 'DESC']);
if(!$last) $lastrowid=-1; if(!$last) $lastrowid=-1;
@ -139,51 +173,40 @@ class ScrumRepository extends ServiceEntityRepository
else else
$giteaassignees=[]; $giteaassignees=[];
$giteacollaborators=$this->giteaservice->getOrgateams($scrum->getGiteajson()["owner"]["login"]); // Temps d'execution
if($giteacollaborators&&is_array($giteacollaborators)) { $this->showtime(false,"Récupérer info ninegitea");
foreach($giteacollaborators as $team) {
$giteamembers=$this->giteaservice->getTeammembers($team->id); // Récupérer les intervenants
if($giteamembers&&is_array($giteamembers)) { $giteacollaborators=$this->giteaservice->getAssignees($scrum->getGiteajson()["owner"]["login"],$scrum->getGiteajson()["name"]);
foreach($giteamembers as $giteamember) {
if(!in_array($giteamember,$giteaassignees))
array_push($giteaassignees,$giteamember);
}
}
}
}
$giteacollaborators=$this->giteaservice->getCollaborators($scrum->getGiteajson()["owner"]["login"],$scrum->getGiteajson()["name"]);
if(!is_array($giteacollaborators)) die("Probleme de connexion avec gitea veuillez vous <a href='/logout'>reconnecter</a>"); if(!is_array($giteacollaborators)) die("Probleme de connexion avec gitea veuillez vous <a href='/logout'>reconnecter</a>");
foreach($giteacollaborators as $giteacollaborator) { foreach($giteacollaborators as $giteacollaborator) {
if(!in_array($giteacollaborator,$giteaassignees)) if(!in_array($giteacollaborator,$giteaassignees))
array_push($giteaassignees,$giteacollaborator); array_push($giteaassignees,$giteacollaborator);
} }
// Temps d'execution
$this->showtime(false,"Récupérer les intervenants");
// Récupérer les milestones de gitea // Récupérer les milestones de gitea
$giteamilestones=$this->giteaservice->getMilestones($scrum->getGiteajson()["owner"]["login"],$scrum->getGiteajson()["name"],"?state=".($viewclosed=="true"?"all":"open")); $giteamilestones=$this->giteaservice->getMilestones($scrum->getGiteajson()["owner"]["login"],$scrum->getGiteajson()["name"],"?state=".($viewclosed=="true"?"all":"open"));
if(!is_array($giteamilestones)) die("Probleme de connexion avec gitea veuillez vous <a href='/logout'>reconnecter</a>"); if(!is_array($giteamilestones)) die("Probleme de connexion avec gitea veuillez vous <a href='/logout'>reconnecter</a>");
$keysort = array_column($giteamilestones, 'title'); $keysort = array_column($giteamilestones, 'title');
array_multisort($keysort, SORT_DESC, $giteamilestones); array_multisort($keysort, SORT_DESC, $giteamilestones);
// Récupérer les labels de gitea // Temps d'execution
$gitealabels=$this->giteaservice->getLabels($scrum->getGiteajson()["owner"]["login"],$scrum->getGiteajson()["name"]); $this->showtime(false,"Récupérer les milestones");
// Formatter les labels non colomn/team/priority/type
/*
foreach($gitealabels as $key => $gitealabel) {
if(in_array($gitealabel->id,$giteacolumns)||in_array($gitealabel->id,$giteateams)||in_array($gitealabel->id,$giteaprioritys)||in_array($gitealabel->id,$giteatypes))
unset($gitealabels[$key]);
}
*/
// Récupérer les issues de gitea // Récupérer les issues de gitea
$giteaissues=$this->giteaservice->getIssues($scrum->getGiteajson()["owner"]["login"],$scrum->getGiteajson()["name"],"?state=".($viewclosed=="true"?"all":"open")); $giteaissues=$this->giteaservice->getIssues($scrum->getGiteajson()["owner"]["login"],$scrum->getGiteajson()["name"],"?state=all".(!$forcereload?"&since=".urlencode($lastupdate->format(\DateTime::RFC3339_EXTENDED)):""));
if(!is_array($giteaissues)) die("Probleme de connexion avec gitea veuillez vous <a href='/logout'>reconnecter</a>"); if(!is_array($giteaissues)) die("Probleme de connexion avec gitea veuillez vous <a href='/logout'>reconnecter</a>");
// Temps d'execution
$this->showtime(false,"Récupérer les issues");
// Génération des issues // Génération des issues
$tbgiteaissues=[]; $tbgiteaissues=[];
$fgscrumupdate=false; $fgscrumupdate=false;
$this->datescrumupdate=new \DateTime("01/01/1900"); $updatedates=[];
$this->datescrumupdate->setTimezone(new \DateTimeZone("UTC"));
foreach($giteaissues as $giteaissue) { foreach($giteaissues as $giteaissue) {
@ -215,11 +238,13 @@ class ScrumRepository extends ServiceEntityRepository
if($fgissueupdated) { if($fgissueupdated) {
$updateissue=new \DateTime(json_decode(json_encode($giteaissue), true)["updated_at"]); $updateissue=new \DateTime(json_decode(json_encode($giteaissue), true)["updated_at"]);
$updateissue->setTimezone(new \DateTimeZone("UTC")); $updateissue->setTimezone(new \DateTimeZone("UTC"));
array_push($updatedates,$updateissue);
$closeissue=new \DateTime(json_decode(json_encode($giteaissue), true)["closed_at"]); if($giteaissue->closed_at) {
$closeissue->setTimezone(new \DateTimeZone("UTC")); $closeissue=new \DateTime(json_decode(json_encode($giteaissue), true)["closed_at"]);
$closeissue->setTimezone(new \DateTimeZone("UTC"));
$this->datescrumupdate=max($this->datescrumupdate,$updateissue,$closeissue); array_push($updatedates,$closeissue);
}
$fgscrumupdate=true; $fgscrumupdate=true;
$this->majissue($scrumissue,$giteaissue,false); $this->majissue($scrumissue,$giteaissue,false);
@ -228,30 +253,28 @@ class ScrumRepository extends ServiceEntityRepository
array_push($tbgiteaissues,$giteaissue->number); array_push($tbgiteaissues,$giteaissue->number);
} }
// Placer à closed l'ensemble des issues vu comme open mais qui ne le sont plus // Temps d'execution
if($viewclosed=="false") { $this->showtime(false,"Traiter les issues");
$scrumissues=$scrum->getScrumissues();
foreach($scrumissues as $scrumissue) {
if($scrumissue->getGiteastate()=="open"&&!in_array($scrumissue->getGiteanumber(),$tbgiteaissues)) {
$giteaissue=$this->giteaservice->getIssue($scrum->getGiteajson()["owner"]["login"],$scrum->getGiteajson()["name"],$scrumissue->getGiteanumber());
$fgscrumupdate=true;
// S'il ne trouve pas d'issue c'est qu'elle n'existe plus
if(!$giteaissue) {
// Faudrait supprimer mais pour l'instant pas touche
//dump("netrouvepasissue alors");
//dump($scrumissue->getGiteanumber());
}
// Sinon mise
else $this->majissue($scrumissue,$giteaissue,false);
}
}
}
if($fgscrumupdate) { if($fgscrumupdate) {
$scrum->setUpdatedate($this->datescrumupdate); // Convertir les objets DateTime en timestamps
$this->_em->persist($scrum); $timestamps = array_map(function($date) {
return $date->getTimestamp();
}, $updatedates);
// Trouver le timestamp le plus récent
$mostRecentTimestamp = max($timestamps);
// Créer une nouvelle instance de DateTime à partir du timestamp le plus récent
$mostRecentDate = (new \DateTime())->setTimestamp($mostRecentTimestamp);
// Mettre à jour la date update du scrum
$scrum->setUpdatedate($mostRecentDate);
$this->_em->flush(); $this->_em->flush();
// Temps d'execution
$this->showtime(false,"Mettre à jour le scrum");
} }
} }
@ -315,4 +338,18 @@ class ScrumRepository extends ServiceEntityRepository
$this->_em->persist($scrumissue); $this->_em->persist($scrumissue);
$this->_em->flush(); $this->_em->flush();
} }
private function getMaxDate(\DateTime ...$dates): \DateTime {
// Initialiser la date maximale avec la première date de la liste
$maxDate = $dates[0];
// Comparer chaque date avec la date maximale actuelle
foreach ($dates as $date) {
if ($date > $maxDate) {
$maxDate = $date;
}
}
return $maxDate;
}
} }

View File

@ -222,6 +222,13 @@ class giteaService
} }
else return $response->body; else return $response->body;
} }
public function getassignees($owner,$name) {
$apiurl = $this->url."/repos/$owner/$name/assignees";
$response=$this->api("GET",$apiurl,null,$this->session->get("giteatoken"));
if(!$response||$response->code!="200") return false;
else return $response->body;
}
public function getcollaborators($owner,$name) { public function getcollaborators($owner,$name) {
$apiurl = $this->url."/repos/$owner/$name/collaborators"; $apiurl = $this->url."/repos/$owner/$name/collaborators";
@ -252,8 +259,7 @@ class giteaService
} }
public function getissues($owner,$name,$state="?state=open") { public function getissues($owner,$name,$state="?state=open") {
$apiurl = $this->url."/repos/$owner/$name/issues".$state."&type=issues"; $apiurl = $this->url."/repos/$owner/$name/issues".$state.($state==""?"?":"&")."type=issues";
$page=1; $page=1;
$limit=20; $limit=20;
$issues=[]; $issues=[];