@@ -6,45 +6,47 @@ class StatusController < ActionController::API
66 skip_before_action :verify_authenticity_token , raise : false
77
88 COMPONENT_META = {
9- 'api' => { name : 'API' , description : 'Core REST API services' } ,
10- 'database' => { name : 'Database' , description : 'PostgreSQL primary database' } ,
11- 'redis' => { name : 'Cache & Background Jobs' , description : 'Redis cache and Sidekiq queue processor' } ,
12- 'websocket' => { name : 'Real-time (WebSocket)' , description : 'ActionCable WebSocket connections' } ,
13- 'sidekiq' => { name : 'Background Jobs (Sidekiq)' , description : 'Async job processing' } ,
14- 'riot_api' => { name : 'Riot API Integration' , description : 'Riot Games data synchronization' }
9+ 'api' => { name : 'API' , description : 'Core REST API services' } ,
10+ 'database' => { name : 'Database' , description : 'PostgreSQL primary database' } ,
11+ 'redis' => { name : 'Cache & Background Jobs' , description : 'Redis cache and Sidekiq queue processor' } ,
12+ 'websocket' => { name : 'Real-time (WebSocket)' , description : 'ActionCable WebSocket connections' } ,
13+ 'sidekiq' => { name : 'Background Jobs (Sidekiq)' , description : 'Async job processing' } ,
14+ 'riot_api' => { name : 'Riot API Integration' , description : 'Riot Games data synchronization' }
1515 } . freeze
1616
1717 def index
18- components = build_component_statuses
19- incidents = build_incidents
20- uptime = build_uptime_history
21- indicator , description = overall_status ( components )
18+ cached = Rails . cache . fetch ( 'status_page/v2' , expires_in : 30 . seconds ) do
19+ components = build_component_statuses
20+ incidents = build_incidents
21+ uptime = build_uptime_history
22+ indicator , description = overall_status ( components )
23+
24+ {
25+ status : { indicator : indicator , description : description } ,
26+ components : components ,
27+ incidents : incidents ,
28+ uptime_history : uptime
29+ }
30+ end
2231
23- render json : {
32+ render json : cached . merge (
2433 page : {
25- id : 'prostaff' ,
26- name : 'ProStaff' ,
27- url : 'https://status.prostaff.gg' ,
28- time_zone : 'UTC' ,
34+ id : 'prostaff' ,
35+ name : 'ProStaff' ,
36+ url : 'https://status.prostaff.gg' ,
37+ time_zone : 'UTC' ,
2938 updated_at : Time . current . iso8601
30- } ,
31- status : {
32- indicator : indicator ,
33- description : description
34- } ,
35- components : components ,
36- incidents : incidents ,
37- uptime_history : uptime
38- } , status : :ok
39+ }
40+ ) , status : :ok
3941 end
4042
4143 private
4244
4345 def build_component_statuses
44- StatusIncident ::COMPONENTS . map do |component |
45- snapshot = StatusSnapshot . for_component ( component ) . order ( checked_at : :desc ) . first
46+ latest = StatusSnapshot . latest_per_component
4647
47- if snapshot
48+ StatusIncident ::COMPONENTS . map do |component |
49+ if ( snapshot = latest [ component ] )
4850 build_component_from_snapshot ( component , snapshot )
4951 else
5052 build_component_live ( component )
@@ -55,13 +57,13 @@ def build_component_statuses
5557 def build_component_from_snapshot ( component , snapshot )
5658 meta = COMPONENT_META [ component ]
5759 {
58- id : component ,
59- name : meta [ :name ] ,
60- status : snapshot . status ,
61- description : meta [ :description ] ,
60+ id : component ,
61+ name : meta [ :name ] ,
62+ status : snapshot . status ,
63+ description : meta [ :description ] ,
6264 response_time_ms : snapshot . response_time_ms ,
63- last_checked_at : snapshot . checked_at . iso8601 ,
64- updated_at : snapshot . updated_at . iso8601
65+ last_checked_at : snapshot . checked_at . iso8601 ,
66+ updated_at : snapshot . updated_at . iso8601
6567 }
6668 end
6769
@@ -70,13 +72,13 @@ def build_component_live(component)
7072 result = live_check ( component )
7173
7274 {
73- id : component ,
74- name : meta [ :name ] ,
75- status : result [ :status ] ,
76- description : meta [ :description ] ,
75+ id : component ,
76+ name : meta [ :name ] ,
77+ status : result [ :status ] ,
78+ description : meta [ :description ] ,
7779 response_time_ms : result [ :response_time_ms ] ,
78- last_checked_at : Time . current . iso8601 ,
79- updated_at : Time . current . iso8601
80+ last_checked_at : Time . current . iso8601 ,
81+ updated_at : Time . current . iso8601
8082 }
8183 end
8284
@@ -120,24 +122,25 @@ def build_incidents
120122
121123 def serialize_incident ( incident )
122124 {
123- id : incident . id ,
124- title : incident . title ,
125- body : incident . body ,
126- severity : incident . severity ,
127- status : incident . status ,
125+ id : incident . id ,
126+ title : incident . title ,
127+ body : incident . body ,
128+ severity : incident . severity ,
129+ status : incident . status ,
128130 affected_components : incident . affected_components ,
129- started_at : incident . started_at . iso8601 ,
130- resolved_at : incident . resolved_at &.iso8601 ,
131- postmortem : incident . postmortem ,
132- updates : incident . updates . order ( created_at : :desc ) . map do |u |
131+ started_at : incident . started_at . iso8601 ,
132+ resolved_at : incident . resolved_at &.iso8601 ,
133+ postmortem : incident . postmortem ,
134+ updates : incident . updates . order ( created_at : :desc ) . map do |u |
133135 { id : u . id , status : u . status , body : u . body , created_at : u . created_at . iso8601 }
134136 end
135137 }
136138 end
137139
138140 def build_uptime_history
141+ bulk = StatusSnapshot . bulk_uptime_by_day ( days : 90 )
139142 StatusIncident ::COMPONENTS . each_with_object ( { } ) do |component , hash |
140- hash [ component ] = StatusSnapshot . uptime_by_day ( component : component , days : 90 )
143+ hash [ component ] = bulk [ component ] || [ ]
141144 end
142145 rescue StandardError => e
143146 Rails . logger . error ( "[STATUS] Failed to build uptime history: #{ e . message } " )
0 commit comments