From dc0992374c71d4f209145d8fc8a4225e5726ff09 Mon Sep 17 00:00:00 2001 From: Wong Hoi Sing Edison Date: Sat, 20 Oct 2012 17:11:00 +0800 Subject: [PATCH] Issue #1511112 by fgm, blueyed and hswong3i: git_deploy slows down module install/enable massively. --- git_deploy.module | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/git_deploy.module b/git_deploy.module index e35ff7c..36b2b83 100644 --- a/git_deploy.module +++ b/git_deploy.module @@ -30,6 +30,15 @@ function git_deploy_system_info_alter(&$info, $file, $type = NULL) { // Theoretically /.git could exist. if ($directory && file_exists($git_dir)) { $git = "git --git-dir $git_dir"; + // Get cached values and return ASAP. + exec("$git rev-parse --verify HEAD 2>&1", $head_hash); + $head_hash = $head_hash[0]; + if ($cache = cache_get("git_deploy:$directory:$head_hash")) { + foreach (array('datestamp', 'project', 'version') as $key) { + $info[$key] = isset($cache->data[$key]) ? $cache->data[$key] : NULL; + } + return; + } // Find first the project name based on fetch URL. // Eat error messages. >& is valid on Windows, too. Also, $output does // not need initialization because it's taken by reference. @@ -81,6 +90,11 @@ function git_deploy_system_info_alter(&$info, $file, $type = NULL) { if ($datestamp && is_numeric($datestamp[0])) { $info['datestamp'] = $datestamp[0]; } + // Save values into cache. + foreach (array('datestamp', 'project', 'version') as $key) { + $cache[$key] = isset($info[$key]) ? $info[$key] : NULL; + } + cache_set("git_deploy:$directory:$head_hash", $cache); } } } -- 1.7.9.5