@@ -27,6 +27,12 @@ defmodule ComponentsGuideWeb.LatencyComparisonLive do
27
27
| form_values: form_values
28
28
}
29
29
end
30
+
31
+ def get_fastest_slowest_responses ( % __MODULE__ { responses: nil } ) , do: nil
32
+
33
+ def get_fastest_slowest_responses ( % __MODULE__ { responses: responses } ) do
34
+ Enum . min_max_by ( responses , fn response -> response . timings . duration end )
35
+ end
30
36
end
31
37
32
38
@ impl true
@@ -61,44 +67,39 @@ defmodule ComponentsGuideWeb.LatencyComparisonLive do
61
67
</ p >
62
68
</ div >
63
69
<% end %>
70
+ <%= if tuple = State . get_fastest_slowest_responses ( @ state ) do %>
71
+ <% { fastest , slowest } = tuple %>
72
+ < ul class = "list-none " >
73
+ < li > Fastest is <%= fastest . url %> in < data > <%= System . convert_time_unit ( fastest . timings . duration , :native , :millisecond ) %> ms</ data > </ li >
74
+ < li > Slowest is <%= slowest . url %> in < data > <%= System . convert_time_unit ( slowest . timings . duration , :native , :millisecond ) %> ms</ data > </ li >
75
+ </ ul >
76
+ <% end %>
64
77
</ output >
65
78
"""
66
79
end
67
80
68
- defp assign_state ( socket , state ) do
69
- assign ( socket , state: state )
70
- end
81
+ defp assign_state ( socket , state ) , do: assign ( socket , state: state )
71
82
72
83
@ impl true
73
- def mount ( % { } , _session , socket ) do
84
+ def mount ( params , _session , socket ) do
74
85
socket = assign ( socket , page_title: "Latency Comparison" )
75
86
87
+ section = Map . get ( params , "section" )
88
+ default_urls = default_urls ( section )
89
+
76
90
state = State . default ( )
77
- socket = assign_state ( socket , state )
91
+
92
+ socket =
93
+ socket
94
+ |> assign_state ( state )
95
+ |> assign ( :default_urls , default_urls )
78
96
79
97
{ :ok , socket }
80
98
end
81
99
82
100
@ impl true
83
101
def handle_event ( "submitted" , form_values = % { "user_url" => user_url } , socket ) do
84
- urls = [
85
- "https://workers.cloudflare.com/cf.json" ,
86
- "https://components-guide-deno.deno.dev/cf.json" ,
87
- "https://api.github.com/rate_limit" ,
88
- "https://unpkg.com/robots.txt" ,
89
- "https://api.npmjs.org/downloads/point/last-month/react" ,
90
- "https://cdn.jsdelivr.net/npm/[email protected] /underscore-esm-min.js" ,
91
- "https://unpkg.com/[email protected] /underscore-esm-min.js" ,
92
- # "https://aws.amazon.com/blogs/aws/",
93
- # "https://aws.amazon.com/blogs/aws/feed/",
94
- # "https://cloud.google.com/blog/",
95
- "https://github.blog/" ,
96
- "https://github.blog/feed/" ,
97
- "https://blog.cloudflare.com/" ,
98
- "https://blog.cloudflare.com/rss/" ,
99
- "https://vercel.com/blog" ,
100
- "https://vercel.com/atom"
101
- ]
102
+ urls = socket . assigns [ :default_urls ]
102
103
103
104
urls =
104
105
case URI . new ( user_url ) do
@@ -133,4 +134,49 @@ defmodule ComponentsGuideWeb.LatencyComparisonLive do
133
134
socket = socket |> assign_state ( state )
134
135
{ :noreply , socket }
135
136
end
137
+
138
+ def default_urls ( "dev-blogs" ) do
139
+ [
140
+ "https://aws.amazon.com/blogs/aws/" ,
141
+ "https://aws.amazon.com/blogs/aws/feed/" ,
142
+ "https://cloud.google.com/blog/" ,
143
+ "https://github.blog/" ,
144
+ "https://github.blog/feed/" ,
145
+ "https://blog.cloudflare.com/" ,
146
+ "https://blog.cloudflare.com/rss/" ,
147
+ "https://vercel.com/blog" ,
148
+ "https://vercel.com/atom" ,
149
+ "https://fly.io/blog" ,
150
+ "https://fly.io/blog/feed.xml" ,
151
+ "https://render.com/blog" ,
152
+ "https://render.com/blog/rss.xml"
153
+ ]
154
+ end
155
+
156
+ def default_urls ( "robots.txt" ) do
157
+ [
158
+ "https://github.com/robots.txt" ,
159
+ "https://www.youtube.com/robots.txt" ,
160
+ "https://medium.com/robots.txt" ,
161
+ "https://twitter.com/robots.txt" ,
162
+ "https://instagram.com/robots.txt" ,
163
+ "https://www.apple.com/robots.txt" ,
164
+ "https://www.cloudflare.com/robots.txt" ,
165
+ "https://unpkg.com/robots.txt" ,
166
+ "https://vercel.com/robots.txt" ,
167
+ "https://render.com/robots.txt"
168
+ ]
169
+ end
170
+
171
+ def default_urls ( _ ) do
172
+ [
173
+ "https://workers.cloudflare.com/cf.json" ,
174
+ "https://components-guide-deno.deno.dev/cf.json" ,
175
+ "https://api.github.com/rate_limit" ,
176
+ "https://unpkg.com/robots.txt" ,
177
+ "https://api.npmjs.org/downloads/point/last-month/react" ,
178
+ "https://cdn.jsdelivr.net/npm/[email protected] /underscore-esm-min.js" ,
179
+ "https://unpkg.com/[email protected] /underscore-esm-min.js"
180
+ ]
181
+ end
136
182
end
0 commit comments