Merge remote-tracking branch 'github-seldaek/gh-cache'
By Jordi Boggiano via Jordi Boggiano * github-seldaek/gh-cache: Update changelog Add caching for metadata in github driverpull/701/merge
commit
90e52a0828
|
@ -1,6 +1,6 @@
|
||||||
* 1.0.0-alpha4
|
* 1.0.0-alpha4
|
||||||
|
|
||||||
|
* Added caching of github metadata (faster startup time with custom github VCS repos)
|
||||||
|
|
||||||
* 1.0.0-alpha3 (2012-05-13)
|
* 1.0.0-alpha3 (2012-05-13)
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,7 @@ namespace Composer\Repository\Vcs;
|
||||||
|
|
||||||
use Composer\Downloader\TransportException;
|
use Composer\Downloader\TransportException;
|
||||||
use Composer\Json\JsonFile;
|
use Composer\Json\JsonFile;
|
||||||
|
use Composer\Cache;
|
||||||
use Composer\IO\IOInterface;
|
use Composer\IO\IOInterface;
|
||||||
use Composer\Util\ProcessExecutor;
|
use Composer\Util\ProcessExecutor;
|
||||||
use Composer\Util\RemoteFilesystem;
|
use Composer\Util\RemoteFilesystem;
|
||||||
|
@ -23,6 +24,7 @@ use Composer\Util\RemoteFilesystem;
|
||||||
*/
|
*/
|
||||||
class GitHubDriver extends VcsDriver
|
class GitHubDriver extends VcsDriver
|
||||||
{
|
{
|
||||||
|
protected $cache;
|
||||||
protected $owner;
|
protected $owner;
|
||||||
protected $repository;
|
protected $repository;
|
||||||
protected $tags;
|
protected $tags;
|
||||||
|
@ -47,6 +49,7 @@ class GitHubDriver extends VcsDriver
|
||||||
$this->owner = $match[1];
|
$this->owner = $match[1];
|
||||||
$this->repository = $match[2];
|
$this->repository = $match[2];
|
||||||
$this->originUrl = 'github.com';
|
$this->originUrl = 'github.com';
|
||||||
|
$this->cache = new Cache($this->io, $this->config->get('home').'/cache.github/'.$this->owner.'/'.$this->repository);
|
||||||
|
|
||||||
$this->fetchRootIdentifier();
|
$this->fetchRootIdentifier();
|
||||||
}
|
}
|
||||||
|
@ -115,18 +118,36 @@ class GitHubDriver extends VcsDriver
|
||||||
if ($this->gitDriver) {
|
if ($this->gitDriver) {
|
||||||
return $this->gitDriver->getComposerInformation($identifier);
|
return $this->gitDriver->getComposerInformation($identifier);
|
||||||
}
|
}
|
||||||
if (!isset($this->infoCache[$identifier])) {
|
|
||||||
$composer = $this->getContents($this->getScheme() . '://raw.github.com/'.$this->owner.'/'.$this->repository.'/'.$identifier.'/composer.json');
|
if (preg_match('{[a-f0-9]{40}}i', $identifier) && $res = $this->cache->read($identifier)) {
|
||||||
if (!$composer) {
|
$this->infoCache[$identifier] = JsonFile::parseJson($res);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!isset($this->infoCache[$identifier])) {
|
||||||
|
try {
|
||||||
|
$composer = $this->getContents($this->getScheme() . '://raw.github.com/'.$this->owner.'/'.$this->repository.'/'.$identifier.'/composer.json');
|
||||||
|
} catch (TransportException $e) {
|
||||||
|
if (404 !== $e->getCode()) {
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
|
|
||||||
|
$composer = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($composer) {
|
||||||
$composer = JsonFile::parseJson($composer);
|
$composer = JsonFile::parseJson($composer);
|
||||||
|
|
||||||
if (!isset($composer['time'])) {
|
if (!isset($composer['time'])) {
|
||||||
$commit = JsonFile::parseJson($this->getContents($this->getScheme() . '://api.github.com/repos/'.$this->owner.'/'.$this->repository.'/commits/'.$identifier));
|
$commit = JsonFile::parseJson($this->getContents($this->getScheme() . '://api.github.com/repos/'.$this->owner.'/'.$this->repository.'/commits/'.$identifier));
|
||||||
$composer['time'] = $commit['commit']['committer']['date'];
|
$composer['time'] = $commit['commit']['committer']['date'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (preg_match('{[a-f0-9]{40}}i', $identifier)) {
|
||||||
|
$this->cache->write($identifier, json_encode($composer));
|
||||||
|
}
|
||||||
|
|
||||||
$this->infoCache[$identifier] = $composer;
|
$this->infoCache[$identifier] = $composer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue