From 81bbdd1aef0293a1fafc2aee71c92a996373d4b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Schw=C3=B6rer?= Date: Sun, 16 Oct 2022 20:42:12 +0200 Subject: [PATCH] Added more fine-granular transactions to EGG2 --- www/extern/egg/ExtendedGitGraph2.php | 4 +- www/extern/egg/RemoteSource.php | 56 ++++++++++++++++------------ 2 files changed, 35 insertions(+), 25 deletions(-) diff --git a/www/extern/egg/ExtendedGitGraph2.php b/www/extern/egg/ExtendedGitGraph2.php index 263995a..c41225f 100644 --- a/www/extern/egg/ExtendedGitGraph2.php +++ b/www/extern/egg/ExtendedGitGraph2.php @@ -62,7 +62,6 @@ class ExtendedGitGraph2 implements ILogger try { $this->db->open(); - $this->db->beginTransaction(); $this->proclog("Start incremental data update"); $this->proclog(); @@ -76,11 +75,12 @@ class ExtendedGitGraph2 implements ILogger $this->proclog(); } + $this->db->beginTransaction(); $this->db->deleteOldSources(array_map(function (IRemoteSource $v){ return $v->getName(); }, $this->sources)); + $this->db->commitTransaction(); $this->proclog("Update finished."); - $this->db->commitTransaction(); $this->proclog("Data written."); $this->db->close(); diff --git a/www/extern/egg/RemoteSource.php b/www/extern/egg/RemoteSource.php index 7a01e61..5a646f1 100644 --- a/www/extern/egg/RemoteSource.php +++ b/www/extern/egg/RemoteSource.php @@ -51,49 +51,59 @@ abstract class StandardGitConnection implements IRemoteSource { $this->preUpdate(); + $db->beginTransaction(); $repos = $this->listAndUpdateRepositories($db); + $db->commitTransaction(); $anyChanged = false; foreach ($repos as $repo) { - $branches = $this->listAndUpdateBranches($db, $repo); - $db->setUpdateDateOnRepository($repo); - - $repo_changed = false; - foreach ($branches as $branch) + $db->beginTransaction(); { - if ($branch->HeadFromAPI === $branch->Head) + $branches = $this->listAndUpdateBranches($db, $repo); + $db->setUpdateDateOnRepository($repo); + + $repo_changed = false; + foreach ($branches as $branch) { + if ($branch->HeadFromAPI === $branch->Head) + { + $db->setUpdateDateOnBranch($branch); + $this->logger->proclog("Branch: [" . $this->name . "|" . $repo->Name . "|" . $branch->Name . "] is up to date"); + continue; + } + + $commits = $this->listAndUpdateCommits($db, $repo, $branch); $db->setUpdateDateOnBranch($branch); - $this->logger->proclog("Branch: [" . $this->name . "|" . $repo->Name . "|" . $branch->Name . "] is up to date"); - continue; + if (count($commits) === 0) + { + $this->logger->proclog("Branch: [" . $this->name . "|" . $repo->Name . "|" . $branch->Name . "] has no new commits"); + continue; + } + + $this->logger->proclog("Found " . count($commits) . " new commits in Branch: [" . $this->name . "|" . $repo->Name . "|" . $branch->Name . "]"); + + $repo_changed = true; + $db->setChangeDateOnBranch($branch); } - $commits = $this->listAndUpdateCommits($db, $repo, $branch); - $db->setUpdateDateOnBranch($branch); - if (count($commits) === 0) - { - $this->logger->proclog("Branch: [" . $this->name . "|" . $repo->Name . "|" . $branch->Name . "] has no new commits"); - continue; - } - - $this->logger->proclog("Found " . count($commits) . " new commits in Branch: [" . $this->name . "|" . $repo->Name . "|" . $branch->Name . "]"); - - $repo_changed = true; - $db->setChangeDateOnBranch($branch); + if ($repo_changed) $db->setChangeDateOnRepository($repo); + if ($repo_changed) $anyChanged = true; } - - if ($repo_changed) $db->setChangeDateOnRepository($repo); - if ($repo_changed) $anyChanged = true; + $db->commitTransaction(); } if ($anyChanged) { + $db->beginTransaction(); $db->deleteDanglingCommitdata($this->name); + $db->commitTransaction(); } + $db->beginTransaction(); $this->postUpdate(); + $db->commitTransaction(); } /**