■ ■ ■ ■ ■ ■
backend/app/controllers/programs_controller.rb
| skipped 26 lines |
27 | 27 | | render status: 429, json: { message: I18n.t('errors.controllers.programs.rate_limited'), data: rate_limited } |
28 | 28 | | end |
29 | 29 | | end |
30 | | - | end |
31 | 30 | | |
32 | | - | private |
| 31 | + | private |
33 | 32 | | |
34 | | - | def launch_sync(platforms) |
35 | | - | rate_limited = [] |
36 | | - | platforms.each do |platform| |
37 | | - | rate_limited << rate_limited?(platform) |
38 | | - | next if rate_limited.include?(platform.name) |
| 33 | + | def launch_sync(platforms) |
| 34 | + | rate_limited = [] |
| 35 | + | platforms.each do |platform| |
| 36 | + | rate_limited << rate_limited?(platform) |
| 37 | + | next if rate_limited.include?(platform.name) |
39 | 38 | | |
40 | | - | update_programs(platform) |
41 | | - | platform.programs.last.update(updated_at: Time.now) if platform.programs.last |
42 | | - | end |
| 39 | + | update_programs(platform) |
| 40 | + | platform.programs.last.update(updated_at: Time.now) if platform.programs.last |
| 41 | + | end |
43 | 42 | | |
44 | | - | rate_limited |
45 | | - | end |
| 43 | + | rate_limited |
| 44 | + | end |
46 | 45 | | |
47 | | - | # In order to avoid that several refreshes are launched at the same time so as not to overload the platform's API |
48 | | - | def rate_limited?(platform) |
49 | | - | return unless platform.programs.last && Time.now - platform.programs.last.updated_at < 1800 |
| 46 | + | # In order to avoid that several refreshes are launched at the same time so as not to overload the platform's API |
| 47 | + | def rate_limited?(platform) |
| 48 | + | return unless platform.programs.last && Time.now - platform.programs.last.updated_at < 1800 |
50 | 49 | | |
51 | | - | platform.name |
52 | | - | end |
| 50 | + | platform.name |
| 51 | + | end |
53 | 52 | | |
54 | | - | def query_params |
55 | | - | params[:program] || '' |
| 53 | + | def query_params |
| 54 | + | params[:program] || '' |
| 55 | + | end |
56 | 56 | | end |
57 | 57 | | |