Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC: Cache template. #172

Open
caugner opened this issue Jul 5, 2016 · 2 comments
Open

RFC: Cache template. #172

caugner opened this issue Jul 5, 2016 · 2 comments

Comments

@caugner
Copy link

caugner commented Jul 5, 2016

Couscous currently doesn't cache the template.

This has two disadvantages:

  1. Preview isn't really (*) possible when offline.
  2. It retrieves data that it already retrieved before.

(*) It is possible though to checkout the template repository locally and provide this path as a file:// url.

Caching the template repository would solve these problems:

// FetchRemoteTemplate.php

private function fetchGitTemplate($gitUrl)
{
    $this->logger->notice('Fetching template from {url}', ['url' => $gitUrl]);

    $gitUrlHash = sha1($gitUrl);
    $directory = getcwd() . '/.couscous/templates/' . $gitUrlHash;

    $this->git->cloneOrUpdateRepository($gitUrl, $directory);

    return $directory;
}
// Git.php

    public function cloneOrUpdateRepository($url, $directory)
    {
        if (!file_exists($directory)) {
            $this->commandRunner->run("git clone $url $directory");
        } else {
            $this->commandRunner->run("cd $directory; git reset --hard; git pull; cd " . getcwd());
        }
    }

What do you think of this?

@mnapoli
Copy link
Member

mnapoli commented Jul 9, 2016

Sounds like a very good idea! (sorry for the delay)

@mnapoli
Copy link
Member

mnapoli commented Jul 9, 2016

(FYI there's the Git helper for doing git operations)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants