1
0

Improve egg:refresh performance a bit

This commit is contained in:
Mike Schwörer 2022-10-17 23:03:42 +02:00
parent 1084bd36a6
commit 16051928c1
Signed by: Mikescher
GPG Key ID: D3C7172E0A70F8CF
2 changed files with 38 additions and 7 deletions

View File

@ -104,9 +104,22 @@ class EGGDatabase
}
$stmt->execute();
$r = $stmt->fetchAll(PDO::FETCH_ASSOC);
return $r;
return $stmt->fetchAll(PDO::FETCH_ASSOC);
}
public function sql_query_assoc_pre_prep(PDOStatement $stmt, array $params)
{
$stmt->closeCursor();
foreach ($params as $p)
{
if (strpos($stmt->queryString, $p[0]) !== FALSE) $stmt->bindValue($p[0], $p[1], $p[2]);
}
$stmt->execute();
return $stmt->fetchAll(PDO::FETCH_ASSOC);
}
public function sql_exec_prep(string $query, array $params)
@ -123,6 +136,20 @@ class EGGDatabase
return $stmt->rowCount();
}
public function sql_exec_pre_prep(PDOStatement $stmt, array $params)
{
$stmt->closeCursor();
foreach ($params as $p)
{
if (str_contains($stmt->queryString, $p[0])) $stmt->bindValue($p[0], $p[1], $p[2]);
}
$stmt->execute();
return $stmt->rowCount();
}
/**
* @param string $url
* @param string $name
@ -224,17 +251,22 @@ class EGGDatabase
public function insertNewCommits(string $source, Repository $repo, Branch $branch, array $commits) {
$this->logger->proclog("Inserting " . count($commits) . " (new) commits into [" . $source . "|" . $repo->Name . "|" . $branch->Name . "]");
$stmtAddCommit = $this->pdo->prepare("INSERT INTO commits ([branch_id], [hash]) VALUES (:brid, :sha)");
$stmtAddMD = $this->pdo->prepare("INSERT OR IGNORE INTO metadata ([hash], [author_name], [author_email], [committer_name], [committer_email], [message], [date], [parent_commits]) VALUES (:sha, :an, :am, :cn, :cm, :msg, :dat, :prt)");
$stmtGetID = $this->pdo->prepare("SELECT id FROM commits WHERE [branch_id] = :brid AND [Hash] = :sha");
foreach ($commits as $commit)
{
$strparents = implode(";", $commit->Parents);
$this->sql_exec_prep("INSERT INTO commits ([branch_id], [hash]) VALUES (:brid, :sha)",
$this->sql_exec_pre_prep($stmtAddCommit,
[
[":brid", $branch->ID, PDO::PARAM_INT],
[":sha", $commit->Hash, PDO::PARAM_STR],
]);
$this->sql_exec_prep("INSERT OR IGNORE INTO metadata ([hash], [author_name], [author_email], [committer_name], [committer_email], [message], [date], [parent_commits]) VALUES (:sha, :an, :am, :cn, :cm, :msg, :dat, :prt)",
$this->sql_exec_pre_prep($stmtAddMD,
[
[":sha", $commit->Hash, PDO::PARAM_STR],
[":an", $commit->AuthorName, PDO::PARAM_STR],
@ -246,7 +278,7 @@ class EGGDatabase
[":prt", $strparents, PDO::PARAM_STR],
]);
$dbid = $this->sql_query_assoc_prep("SELECT id FROM commits WHERE [branch_id] = :brid AND [Hash] = :sha",
$dbid = $this->sql_query_assoc_pre_prep($stmtGetID,
[
[":brid", $branch->ID, PDO::PARAM_INT],
[":sha", $commit->Hash, PDO::PARAM_STR],

View File

@ -90,7 +90,6 @@ abstract class StandardGitConnection implements IRemoteSource
if ($repo_changed) $anyChanged = true;
}
$this->logger->proclog("Committing SQL-transaction for [" . $this->name . "|" . $repo->Name . "]");
$db->commitTransaction();
}
@ -347,7 +346,7 @@ abstract class StandardGitConnection implements IRemoteSource
}
if ($branch->Head === null) {
$this->logger->proclog("HEAD pointer in new Branch: [" . $this->name . "|" . $repo->Name . "|" . $branch->Name . "] set to ". $branch->HeadFromAPI ." Queried " . count($newcommits) . " commits (reused $reusedFromExisting commits from DB)");
$this->logger->proclog("HEAD pointer in new Branch: [" . $this->name . "|" . $repo->Name . "|" . $branch->Name . "] set to {".substr($branch->HeadFromAPI ?? 'NULL', 0, 8)."} - Queried " . count($newcommits) . " commits (reused $reusedFromExisting commits from DB)");
} else {
$this->logger->proclog("HEAD pointer in Branch: [" . $this->name . "|" . $repo->Name . "|" . $branch->Name . "] no longer matches. Re-queried all " . count($newcommits) . " commits (old HEAD := {".substr($branch->Head ?? 'NULL', 0, 8)."}, missing: [" . join(", ", array_map(function($p){return substr($p ?? 'NULL', 0, 8);}, $next_sha)) . "] )");
}