@@ -124,37 +124,36 @@ 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 = [ ]
129-
130- collections . each do |collection |
131- items_for_collection ( collection ) &.each do |item |
132- if item . match? ( USERNAME_AND_REPO_REGEX )
133- all_repos << item
134- elsif item . match? ( USERNAME_REGEX )
135- all_users << item
136- end
137- end
138- end
127+ repos , users = collect_all_collection_items
128+ prefetch_repos! ( repos )
129+ prefetch_users! ( users )
130+
131+ NewOctokit . global_prefetch_done!
132+ end
139133
140- all_repos . uniq!
141- all_users . uniq!
134+ def collect_all_collection_items
135+ all_items = collections . flat_map { | c | items_for_collection ( c ) || [ ] }
142136
143- # Batch repos in chunks to stay within GraphQL query limits
144- all_repos . each_slice ( GRAPHQL_BATCH_SIZE ) do |batch |
137+ repos = all_items . select { |item | item . match? ( USERNAME_AND_REPO_REGEX ) } . uniq
138+ users = all_items
139+ . select { |item | item . match? ( USERNAME_REGEX ) && !item . match? ( USERNAME_AND_REPO_REGEX ) }
140+ . uniq
141+
142+ [ repos , users ]
143+ end
144+
145+ def prefetch_repos! ( repos )
146+ repos . each_slice ( GRAPHQL_BATCH_SIZE ) do |batch |
145147 cache_repos_exist_check! ( batch )
146148 end
149+ end
147150
148- # Batch users in chunks
149- all_users . each_slice ( GRAPHQL_BATCH_SIZE ) do |batch |
151+ def prefetch_users! ( users )
152+ users . each_slice ( GRAPHQL_BATCH_SIZE ) do |batch |
150153 cache_users_exist_check! ( batch )
151154 end
152155
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 |
156+ users_not_found_from ( users ) . each_slice ( GRAPHQL_BATCH_SIZE ) do |batch |
156157 cache_orgs_exist_check! ( batch )
157158 end
158-
159- NewOctokit . global_prefetch_done!
160159end
0 commit comments