1
0

Fix egg:deleteDanglingCommitdata()

This commit is contained in:
Mike Schwörer 2022-10-17 12:15:28 +02:00
parent 8ed58917ff
commit 18af582343
Signed by: Mikescher
GPG Key ID: D3C7172E0A70F8CF
2 changed files with 11 additions and 5 deletions

View File

@ -355,11 +355,19 @@ class EGGDatabase
public function deleteDanglingCommitdata(string $name) public function deleteDanglingCommitdata(string $name)
{ {
$db = $this->sql_query_assoc_prep("SELECT metadata.hash FROM metadata LEFT JOIN commits WHERE commits.hash IS NULL", []); $hashes = $this->sql_query_assoc_prep("SELECT metadata.hash FROM metadata LEFT JOIN commits ON metadata.hash = commits.hash WHERE commits.hash IS NULL", []);
if (count($db) === 0) return; if (count($hashes) === 0) return;
$this->logger->proclog("Delete ".count($db)." dangling commits [" . $name . "] from database (no longer linked)"); $this->logger->proclog("Deleting ".count($hashes)." dangling commits [" . $name . "] from database (no longer linked)");
$this->beginTransaction();
foreach ($hashes as $hash) {
$this->sql_query_assoc_prep("DELETE FROM metadata WHERE hash = :hash", [ [":hash", $hash, PDO::PARAM_STR] ]);
}
$this->commitTransaction();
$this->logger->proclog("Succesfully deleted ".count($hashes)." dangling commits");
} }
/** /**

View File

@ -466,7 +466,6 @@ class GithubConnection extends StandardGitConnection
protected function queryCommits($reponame, $branchname, $startsha) protected function queryCommits($reponame, $branchname, $startsha)
{ {
$url = Utils::sharpFormat(self::API_COMMITSLIST, [ 'repo'=>$reponame, 'sha'=>$startsha ]); $url = Utils::sharpFormat(self::API_COMMITSLIST, [ 'repo'=>$reponame, 'sha'=>$startsha ]);
$this->logger->proclog("Query commits from: [" . $this->name . "|" . $reponame . "|" . $branchname . "] continuing at {" . substr($startsha, 0, 8) . "}");
return Utils::getJSONWithTokenAuth($this->logger, $url, $this->apitoken); return Utils::getJSONWithTokenAuth($this->logger, $url, $this->apitoken);
} }
@ -581,7 +580,6 @@ class GiteaConnection extends StandardGitConnection
protected function queryCommits($reponame, $branchname, $startsha) protected function queryCommits($reponame, $branchname, $startsha)
{ {
$url = Utils::sharpFormat(Utils::urlCombine($this->url, self::API_BASE_URL, self::API_COMMIT_LIST), [ 'repo'=>$reponame, 'sha'=>$startsha, 'limit'=>1024 ]); $url = Utils::sharpFormat(Utils::urlCombine($this->url, self::API_BASE_URL, self::API_COMMIT_LIST), [ 'repo'=>$reponame, 'sha'=>$startsha, 'limit'=>1024 ]);
$this->logger->proclog("Query commits from: [" . $this->name . "|" . $reponame . "|" . $branchname . "] continuing at {" . substr($startsha, 0, 8) . "}");
return Utils::getJSONWithTokenBasicAuth($this->logger, $url, $this->username, $this->password); return Utils::getJSONWithTokenBasicAuth($this->logger, $url, $this->username, $this->password);
} }