Skip to content

Commit 9289bf1

Browse files
committed
Synchronise forward if we complete backward synchronisation
1 parent e767097 commit 9289bf1

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

app/models/hosts/gitlab.rb

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,17 +304,46 @@ def crawl_repositories_async
304304
end
305305

306306
def crawl_repositories
307+
# legacy way to synchronize on ecosyste.ms
308+
crawl_repositories_backwards
309+
end
310+
311+
def crawl_repositories_two_ways
312+
# new experimental way to synchronize
313+
if ! crawl_repositories_backwards
314+
crawl_repositories_forward
315+
end
316+
end
317+
318+
def crawl_repositories_backwards
307319
last_id = REDIS.get("gitlab_last_id:#{@host.id}")
308320
repos = api_client.projects(per_page: 100, archived: false, id_before: last_id, simple: true)
309321
if repos.present? && repos.any?
310322
repos.reject! { |repo| repo.dig("namespace", "kind") == "user" } if ENV["SKIP_USER_REPOS"]
311323
repos.each { |repo| @host.sync_repository(repo["path_with_namespace"], uuid: repo["id"]) }
312324
REDIS.set("gitlab_last_id:#{@host.id}", repos.last["id"])
325+
return true
313326
end
314327
rescue *IGNORABLE_EXCEPTIONS
315328
nil
316329
end
317330

331+
def crawl_repositories_forward
332+
recent_id = REDIS.get("gitlab_recent_id:#{@host.id}")
333+
if recent_id.nil?
334+
recent_id = @host.repositories.maximum(:id)
335+
end
336+
repos = api_client.projects(per_page: 100, archived: false, id_after: recent_id, simple: true)
337+
repos.reject! { |repo| repo.dig("namespace", "kind") == "user" } if ENV["SKIP_USER_REPOS"]
338+
if repos.present?
339+
repos.each { |repo| @host.sync_repository(repo["path_with_namespace"], uuid: repo["id"]) }
340+
REDIS.set("gitlab_recent_id:#{@host.id}", repos.last["id"])
341+
end
342+
rescue *IGNORABLE_EXCEPTIONS
343+
nil
344+
end
345+
346+
318347
def load_owner_repos_names(owner)
319348
if owner.user?
320349
api_client.user_projects(owner.login, per_page: 100, archived: false, simple: true).map { |repo| repo["path_with_namespace"] }

lib/tasks/dinum.rake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ module Dinum
130130
host_reset(host) if host.repositories_count == 0
131131
loop do
132132
repo_count = host.repositories_count
133-
host.crawl_repositories
133+
host.crawl_repositories_two_ways
134134
sleep 1
135135
break if host.reload.repositories_count == repo_count
136136
end

0 commit comments

Comments
 (0)