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)
{
$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
$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);
$updateissue=new \DateTime($giteaissue->updated_at);
$updateissue=new \DateTime(json_decode(json_encode($giteaissue), true)["updated_at"]);
$updateissue->setTimezone(new \DateTimeZone("UTC"));
$lastupdate=$scrumissue->getScrum()->getUpdatedate();

View File

@ -13,13 +13,32 @@ class ScrumRepository extends ServiceEntityRepository
{
private $session;
private $firstcolumn;
private $datescrumupdate;
private $totalTime;
private $startTime;
private $showTime;
public function __construct(ManagerRegistry $registry,giteaService $giteaservice,SessionInterface $session)
{
parent::__construct($registry, Scrum::class);
$this->giteaservice = $giteaservice;
$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) {
@ -40,17 +59,30 @@ class ScrumRepository extends ServiceEntityRepository
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");
// Récupérer les labels de gitea
$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>");
$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
$scrumcolumns=$scrum->getScrumcolumns();
foreach($scrumcolumns as $scrumcolumn) {
$gitealabel=$this->giteaservice->getLabel($scrum->getGiteajson()["owner"]["login"],$scrum->getGiteajson()["name"],$scrumcolumn->getGiteaid());
if(!$gitealabel) {
if(!in_array($scrumcolumn->getGiteaid(),$giteaidlabels)) {
$this->_em->remove($scrumcolumn);
$this->_em->flush();
}
@ -59,8 +91,7 @@ class ScrumRepository extends ServiceEntityRepository
// S'assurer que nos teams existes toujours
$scrumteams=$scrum->getScrumteams();
foreach($scrumteams as $scrumteam) {
$gitealabel=$this->giteaservice->getLabel($scrum->getGiteajson()["owner"]["login"],$scrum->getGiteajson()["name"],$scrumteam->getGiteaid());
if(!$gitealabel) {
if(!in_array($scrumteam->getGiteaid(),$giteaidlabels)) {
$this->_em->remove($scrumteam);
$this->_em->flush();
}
@ -69,8 +100,7 @@ class ScrumRepository extends ServiceEntityRepository
// S'assurer que nos prioritys existes toujours
$scrumprioritys=$scrum->getScrumprioritys();
foreach($scrumprioritys as $scrumpriority) {
$gitealabel=$this->giteaservice->getLabel($scrum->getGiteajson()["owner"]["login"],$scrum->getGiteajson()["name"],$scrumpriority->getGiteaid());
if(!$gitealabel) {
if(!in_array($scrumpriority->getGiteaid(),$giteaidlabels)) {
$this->_em->remove($scrumpriority);
$this->_em->flush();
}
@ -79,23 +109,27 @@ class ScrumRepository extends ServiceEntityRepository
// S'assurer que nos types existes toujours
$scrumtypes=$scrum->getScrumtypes();
foreach($scrumtypes as $scrumtype) {
$gitealabel=$this->giteaservice->getLabel($scrum->getGiteajson()["owner"]["login"],$scrum->getGiteajson()["name"],$scrumtype->getGiteaid());
if(!$gitealabel) {
if(!in_array($scrumtype->getGiteaid(),$giteaidlabels)) {
$this->_em->remove($scrumtype);
$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
$scrumsprints=$scrum->getScrumsprints();
foreach($scrumsprints as $scrumsprint) {
$giteamilestone=$this->giteaservice->getMilestone($scrum->getGiteajson()["owner"]["login"],$scrum->getGiteajson()["name"],$scrumsprint->getGiteamilestone());
if(!$giteamilestone) {
if(!in_array($scrumsprint->getGiteamilestone(),$giteaidmilestones)) {
$this->_em->remove($scrumsprint);
$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
$last = $this->_em->getRepository('App:Scrumissue')->findOneBy(["scrum"=>$scrum], ['rowid' => 'DESC']);
if(!$last) $lastrowid=-1;
@ -139,51 +173,40 @@ class ScrumRepository extends ServiceEntityRepository
else
$giteaassignees=[];
$giteacollaborators=$this->giteaservice->getOrgateams($scrum->getGiteajson()["owner"]["login"]);
if($giteacollaborators&&is_array($giteacollaborators)) {
foreach($giteacollaborators as $team) {
$giteamembers=$this->giteaservice->getTeammembers($team->id);
if($giteamembers&&is_array($giteamembers)) {
foreach($giteamembers as $giteamember) {
if(!in_array($giteamember,$giteaassignees))
array_push($giteaassignees,$giteamember);
}
}
}
}
$giteacollaborators=$this->giteaservice->getCollaborators($scrum->getGiteajson()["owner"]["login"],$scrum->getGiteajson()["name"]);
// Temps d'execution
$this->showtime(false,"Récupérer info ninegitea");
// Récupérer les intervenants
$giteacollaborators=$this->giteaservice->getAssignees($scrum->getGiteajson()["owner"]["login"],$scrum->getGiteajson()["name"]);
if(!is_array($giteacollaborators)) die("Probleme de connexion avec gitea veuillez vous <a href='/logout'>reconnecter</a>");
foreach($giteacollaborators as $giteacollaborator) {
if(!in_array($giteacollaborator,$giteaassignees))
array_push($giteaassignees,$giteacollaborator);
}
// Temps d'execution
$this->showtime(false,"Récupérer les intervenants");
// Récupérer les milestones de gitea
$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>");
$keysort = array_column($giteamilestones, 'title');
array_multisort($keysort, SORT_DESC, $giteamilestones);
// Récupérer les labels de gitea
$gitealabels=$this->giteaservice->getLabels($scrum->getGiteajson()["owner"]["login"],$scrum->getGiteajson()["name"]);
// 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]);
}
*/
// Temps d'execution
$this->showtime(false,"Récupérer les milestones");
// 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>");
// Temps d'execution
$this->showtime(false,"Récupérer les issues");
// Génération des issues
$tbgiteaissues=[];
$fgscrumupdate=false;
$this->datescrumupdate=new \DateTime("01/01/1900");
$this->datescrumupdate->setTimezone(new \DateTimeZone("UTC"));
$updatedates=[];
foreach($giteaissues as $giteaissue) {
@ -215,11 +238,13 @@ class ScrumRepository extends ServiceEntityRepository
if($fgissueupdated) {
$updateissue=new \DateTime(json_decode(json_encode($giteaissue), true)["updated_at"]);
$updateissue->setTimezone(new \DateTimeZone("UTC"));
array_push($updatedates,$updateissue);
$closeissue=new \DateTime(json_decode(json_encode($giteaissue), true)["closed_at"]);
$closeissue->setTimezone(new \DateTimeZone("UTC"));
$this->datescrumupdate=max($this->datescrumupdate,$updateissue,$closeissue);
if($giteaissue->closed_at) {
$closeissue=new \DateTime(json_decode(json_encode($giteaissue), true)["closed_at"]);
$closeissue->setTimezone(new \DateTimeZone("UTC"));
array_push($updatedates,$closeissue);
}
$fgscrumupdate=true;
$this->majissue($scrumissue,$giteaissue,false);
@ -228,30 +253,28 @@ class ScrumRepository extends ServiceEntityRepository
array_push($tbgiteaissues,$giteaissue->number);
}
// Placer à closed l'ensemble des issues vu comme open mais qui ne le sont plus
if($viewclosed=="false") {
$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);
}
}
}
// Temps d'execution
$this->showtime(false,"Traiter les issues");
if($fgscrumupdate) {
$scrum->setUpdatedate($this->datescrumupdate);
$this->_em->persist($scrum);
// Convertir les objets DateTime en timestamps
$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();
// Temps d'execution
$this->showtime(false,"Mettre à jour le scrum");
}
}
@ -315,4 +338,18 @@ class ScrumRepository extends ServiceEntityRepository
$this->_em->persist($scrumissue);
$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;
}
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) {
$apiurl = $this->url."/repos/$owner/$name/collaborators";
@ -252,8 +259,7 @@ class giteaService
}
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;
$limit=20;
$issues=[];