@@ -124,37 +124,42 @@ def possible_image_file_names_for_collection(collection)
124124def prefetch_all_collection_items!
125125 return if NewOctokit . global_prefetch_done?
126126
127- all_repos = [ ]
128- all_users = [ ]
127+ repos , users = collect_all_collection_items
128+ prefetch_repos! ( repos )
129+ prefetch_users! ( users )
130+
131+ NewOctokit . global_prefetch_done!
132+ end
133+
134+ def collect_all_collection_items
135+ repos = [ ]
136+ users = [ ]
129137
130138 collections . each do |collection |
131139 items_for_collection ( collection ) &.each do |item |
132140 if item . match? ( USERNAME_AND_REPO_REGEX )
133- all_repos << item
141+ repos << item
134142 elsif item . match? ( USERNAME_REGEX )
135- all_users << item
143+ users << item
136144 end
137145 end
138146 end
139147
140- all_repos . uniq!
141- all_users . uniq!
148+ [ repos . uniq , users . uniq ]
149+ end
142150
143- # Batch repos in chunks to stay within GraphQL query limits
144- all_repos . each_slice ( GRAPHQL_BATCH_SIZE ) do |batch |
151+ def prefetch_repos! ( repos )
152+ repos . each_slice ( GRAPHQL_BATCH_SIZE ) do |batch |
145153 cache_repos_exist_check! ( batch )
146154 end
155+ end
147156
148- # Batch users in chunks
149- all_users . each_slice ( GRAPHQL_BATCH_SIZE ) do |batch |
157+ def prefetch_users! ( users )
158+ users . each_slice ( GRAPHQL_BATCH_SIZE ) do |batch |
150159 cache_users_exist_check! ( batch )
151160 end
152161
153- # Check orgs for users not found
154- not_found_users = users_not_found_from ( all_users )
155- not_found_users . each_slice ( GRAPHQL_BATCH_SIZE ) do |batch |
162+ users_not_found_from ( users ) . each_slice ( GRAPHQL_BATCH_SIZE ) do |batch |
156163 cache_orgs_exist_check! ( batch )
157164 end
158-
159- NewOctokit . global_prefetch_done!
160165end
0 commit comments