Skip to content

Commit 44f56ef

Browse files
committed
Use class-level prefetch flag and verify all batches succeed
1 parent 42ffda3 commit 44f56ef

File tree

2 files changed

+29
-15
lines changed

2 files changed

+29
-15
lines changed

test/collections_test_helper.rb

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def possible_image_file_names_for_collection(collection)
110110
GRAPHQL_BATCH_SIZE = 100
111111

112112
def prefetch_all_collection_items!
113-
return if @_prefetched
113+
return if NewOctokit.global_prefetch_done?
114114

115115
all_repos = []
116116
all_users = []
@@ -128,21 +128,26 @@ def prefetch_all_collection_items!
128128
all_repos.uniq!
129129
all_users.uniq!
130130

131-
# Batch repos in chunks to stay within GraphQL query limits
132-
all_repos.each_slice(GRAPHQL_BATCH_SIZE) do |batch|
133-
cache_repos_exist_check!(batch)
134-
end
131+
begin
132+
# Batch repos in chunks to stay within GraphQL query limits
133+
all_repos.each_slice(GRAPHQL_BATCH_SIZE) do |batch|
134+
cache_repos_exist_check!(batch)
135+
end
135136

136-
# Batch users in chunks
137-
all_users.each_slice(GRAPHQL_BATCH_SIZE) do |batch|
138-
cache_users_exist_check!(batch)
139-
end
137+
# Batch users in chunks
138+
all_users.each_slice(GRAPHQL_BATCH_SIZE) do |batch|
139+
cache_users_exist_check!(batch)
140+
end
140141

141-
# Check orgs for users not found
142-
not_found_users = users_not_found_from(all_users)
143-
not_found_users.each_slice(GRAPHQL_BATCH_SIZE) do |batch|
144-
cache_orgs_exist_check!(batch)
145-
end
142+
# Check orgs for users not found
143+
not_found_users = users_not_found_from(all_users)
144+
not_found_users.each_slice(GRAPHQL_BATCH_SIZE) do |batch|
145+
cache_orgs_exist_check!(batch)
146+
end
146147

147-
@_prefetched = true
148+
# Only mark as done after ALL batch calls completed successfully
149+
NewOctokit.global_prefetch_done!
150+
rescue StandardError => error
151+
warn "Global prefetch failed, falling back to per-test caching: #{error.message}"
152+
end
148153
end

test/test_helper.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ class NewOctokit < Octokit::Client
5959
@@repo_request_count = 0 unless defined? @@repo_request_count
6060
@@user_request_count = 0 unless defined? @@user_request_count
6161
@@messages = [] unless defined? @@messages
62+
@@global_prefetch_done = false unless defined? @@global_prefetch_done
6263

6364
def repos
6465
@@repos
@@ -122,6 +123,14 @@ def self.messages
122123
@@messages
123124
end
124125

126+
def self.global_prefetch_done?
127+
@@global_prefetch_done
128+
end
129+
130+
def self.global_prefetch_done!
131+
@@global_prefetch_done = true
132+
end
133+
125134
# rubocop:enable Style/ClassVars
126135
end
127136

0 commit comments

Comments
 (0)