@@ -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" ] }
0 commit comments