cache label names for MUCH quicker scripts when getting many labels

This commit is contained in:
James 2019-08-24 14:31:26 +01:00
parent d85fe08504
commit a6bb48ef96

View File

@ -1,6 +1,8 @@
<?php <?php
class Repo{ class Repo{
private $cache=[];
public function __construct(Client $client,$user,$repo){ public function __construct(Client $client,$user,$repo){
$this->client=$client; $this->client=$client;
$this->user=$user; $this->user=$user;
@ -29,9 +31,12 @@ class Repo{
} }
public function getLabelByName($name){ public function getLabelByName($name){
$url="repos/{$this->user}/{$this->repo}/labels"; if(!$this->cache['lables']){
$data=$this->client->request($url); $url="repos/{$this->user}/{$this->repo}/labels";
foreach($data as $datum){ $this->cache['lables']=$this->client->request($url);
}
foreach($this->cache['lables'] as $datum){
if($datum->name==$name){ if($datum->name==$name){
$datum->url=$url."/".$datum->id; // not set by api for some reason (bug?) $datum->url=$url."/".$datum->id; // not set by api for some reason (bug?)
return new Label($this,$datum); return new Label($this,$datum);