@@ -27,6 +27,12 @@ defmodule ComponentsGuideWeb.LatencyComparisonLive do
2727 | form_values: form_values
2828 }
2929 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
3036 end
3137
3238 @ impl true
@@ -61,44 +67,39 @@ defmodule ComponentsGuideWeb.LatencyComparisonLive do
6167 </ p >
6268 </ div >
6369 <% 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 %>
6477 </ output >
6578 """
6679 end
6780
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 )
7182
7283 @ impl true
73- def mount ( % { } , _session , socket ) do
84+ def mount ( params , _session , socket ) do
7485 socket = assign ( socket , page_title: "Latency Comparison" )
7586
87+ section = Map . get ( params , "section" )
88+ default_urls = default_urls ( section )
89+
7690 state = State . default ( )
77- socket = assign_state ( socket , state )
91+
92+ socket =
93+ socket
94+ |> assign_state ( state )
95+ |> assign ( :default_urls , default_urls )
7896
7997 { :ok , socket }
8098 end
8199
82100 @ impl true
83101 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/underscore@1.13.6/underscore-esm-min.js" ,
91- "https://unpkg.com/underscore@1.13.6/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 ]
102103
103104 urls =
104105 case URI . new ( user_url ) do
@@ -133,4 +134,49 @@ defmodule ComponentsGuideWeb.LatencyComparisonLive do
133134 socket = socket |> assign_state ( state )
134135 { :noreply , socket }
135136 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/underscore@1.13.6/underscore-esm-min.js" ,
179+ "https://unpkg.com/underscore@1.13.6/underscore-esm-min.js"
180+ ]
181+ end
136182end
0 commit comments