Skip to content

Commit 4777365

Browse files
committed
fix: solve zeitwrk issue into import matches
1 parent 5938c6b commit 4777365

1 file changed

Lines changed: 41 additions & 43 deletions

File tree

Lines changed: 41 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,55 @@
11
# frozen_string_literal: true
22

3-
module Matches
4-
# Fetches match IDs from Riot API for a player and enqueues SyncMatchJob
5-
# for each new match. Returns counts synchronously so the caller can
6-
# respond with meaningful feedback without waiting for individual syncs.
7-
class ImportMatchesService
8-
def initialize(player:, organization:, count: 20, force_update: false)
9-
@player = player
10-
@organization = organization
11-
@count = count
12-
@force_update = force_update
13-
end
3+
# Fetches match IDs from Riot API for a player and enqueues SyncMatchJob
4+
# for each new match. Returns counts synchronously so the caller can
5+
# respond with meaningful feedback without waiting for individual syncs.
6+
class ImportMatchesService
7+
def initialize(player:, organization:, count: 20, force_update: false)
8+
@player = player
9+
@organization = organization
10+
@count = count
11+
@force_update = force_update
12+
end
1413

15-
# @return [Hash] counts: total_matches_found, imported, already_imported, updated
16-
def call
17-
match_ids = fetch_match_ids
18-
tally = { imported: 0, already_imported: 0, updated: 0 }
14+
# @return [Hash] counts: total_matches_found, imported, already_imported, updated
15+
def call
16+
match_ids = fetch_match_ids
17+
tally = { imported: 0, already_imported: 0, updated: 0 }
1918

20-
match_ids.each { |id| process_match(id, tally) }
19+
match_ids.each { |id| process_match(id, tally) }
2120

22-
tally.merge(total_matches_found: match_ids.size)
23-
end
21+
tally.merge(total_matches_found: match_ids.size)
22+
end
2423

25-
private
24+
private
2625

27-
def fetch_match_ids
28-
RiotApiService.new.get_match_history(
29-
puuid: @player.riot_puuid,
30-
region: region,
31-
count: @count
32-
)
33-
end
26+
def fetch_match_ids
27+
RiotApiService.new.get_match_history(
28+
puuid: @player.riot_puuid,
29+
region: region,
30+
count: @count
31+
)
32+
end
3433

35-
def process_match(match_id, tally)
36-
if Match.exists?(riot_match_id: match_id)
37-
handle_existing_match(match_id, tally)
38-
else
39-
SyncMatchJob.perform_later(match_id, @organization.id, region)
40-
tally[:imported] += 1
41-
end
34+
def process_match(match_id, tally)
35+
if Match.exists?(riot_match_id: match_id)
36+
handle_existing_match(match_id, tally)
37+
else
38+
SyncMatchJob.perform_later(match_id, @organization.id, region)
39+
tally[:imported] += 1
4240
end
41+
end
4342

44-
def handle_existing_match(match_id, tally)
45-
if @force_update
46-
SyncMatchJob.perform_later(match_id, @organization.id, region, force_update: true)
47-
tally[:updated] += 1
48-
else
49-
tally[:already_imported] += 1
50-
end
43+
def handle_existing_match(match_id, tally)
44+
if @force_update
45+
SyncMatchJob.perform_later(match_id, @organization.id, region, force_update: true)
46+
tally[:updated] += 1
47+
else
48+
tally[:already_imported] += 1
5149
end
50+
end
5251

53-
def region
54-
@player.region || 'BR'
55-
end
52+
def region
53+
@player.region || 'BR'
5654
end
5755
end

0 commit comments

Comments
 (0)