From a6bb48ef96730001b64de24a656a946bb672283c Mon Sep 17 00:00:00 2001 From: James Date: Sat, 24 Aug 2019 14:31:26 +0100 Subject: [PATCH] cache label names for MUCH quicker scripts when getting many labels --- src/Repo.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Repo.php b/src/Repo.php index 0fdd6f4..fa92669 100644 --- a/src/Repo.php +++ b/src/Repo.php @@ -1,6 +1,8 @@ client=$client; $this->user=$user; @@ -29,9 +31,12 @@ class Repo{ } public function getLabelByName($name){ - $url="repos/{$this->user}/{$this->repo}/labels"; - $data=$this->client->request($url); - foreach($data as $datum){ + if(!$this->cache['lables']){ + $url="repos/{$this->user}/{$this->repo}/labels"; + $this->cache['lables']=$this->client->request($url); + } + + foreach($this->cache['lables'] as $datum){ if($datum->name==$name){ $datum->url=$url."/".$datum->id; // not set by api for some reason (bug?) return new Label($this,$datum);