From 9c332e746f125023bb0d12852972a166bf1204e7 Mon Sep 17 00:00:00 2001 From: Andrew Nesbitt Date: Wed, 7 Feb 2024 16:13:53 +0000 Subject: [PATCH] Update Repository model to use commit count for updates --- app/models/repository.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/models/repository.rb b/app/models/repository.rb index 0303e78..910d67d 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -110,7 +110,7 @@ def count_commits counts = count_commits_internal(dir) commit_hashes = fetch_commits_internal(repo) Commit.upsert_all(commit_hashes) unless commit_hashes.empty? - update(updates) + update(counts) end rescue => e # TODO record error in clone (likely missing repo but also maybe host downtime) @@ -357,10 +357,14 @@ def fetch_commits commits end + def commits_count + commits.count + end + def fetch_commits_internal(repo) commits = [] walker = Rugged::Walker.new(repo) - walker.hide(repo.lookup(last_synced_commit)) if last_synced_commit + walker.hide(repo.lookup(last_synced_commit)) if last_synced_commit && commits_count > 0 walker.sorting(Rugged::SORT_DATE) walker.push(repo.head.target) walker.each do |commit|