Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions htdocs/packages.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@
define('method', 'ssh');
}

$file_is_outdated = function($file_path, $mtime) {
// Subtract 2 minutes from file modified date due to issue with updating "last_activity_at".
// @see: https://gitlab.com/gitlab-org/gitlab-ce/issues/22213
$delta = 120;
return (filemtime($file_path) - $delta) < $mtime;
};

/**
* Retrieves some information about a project's composer.json
*
Expand Down Expand Up @@ -131,15 +138,15 @@
* @param array $project
* @return array Same as $fetch_refs
*/
$load_data = function($project) use ($fetch_refs) {
$load_data = function($project) use ($fetch_refs, $file_is_outdated) {
$file = __DIR__ . "/../cache/{$project['path_with_namespace']}.json";
$mtime = strtotime($project['last_activity_at']);

if (!is_dir(dirname($file))) {
mkdir(dirname($file), 0777, true);
}

if (file_exists($file) && filemtime($file) >= $mtime) {
if (file_exists($file) && !$file_is_outdated($file, $mtime)) {
if (filesize($file) > 0) {
return json_decode(file_get_contents($file));
} else {
Expand Down Expand Up @@ -187,7 +194,7 @@
}

// Regenerate packages_file is needed
if (!file_exists($packages_file) || filemtime($packages_file) < $mtime) {
if (!file_exists($packages_file) || $file_is_outdated($packages_file, $mtime)) {
$packages = array();
foreach ($all_projects as $project) {
if ($package = $load_data($project)) {
Expand Down