Skip to content

perf: improve live reload performance #110

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
11 changes: 8 additions & 3 deletions lib/tableau_dev_server/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ defmodule TableauDevServer.Router do

get "/ws/index.html" do
conn
|> WebSockAdapter.upgrade(Tableau.Websocket, [], timeout: 60_000)
|> WebSockAdapter.upgrade(TableauDevServer.Websocket, [], timeout: 60_000)
|> halt()
end

Expand All @@ -32,12 +32,17 @@ defmodule TableauDevServer.Router do
end

defp recompile(conn, _) do
WebDevUtils.CodeReloader.reload()
if conn.request_path != "/ws" do
WebDevUtils.CodeReloader.reload()
end

conn
end

defp rerender(conn, _) do
Mix.Task.rerun("tableau.build", ["--out", "_site"])
if conn.request_path != "/ws" do
Mix.Task.rerun("tableau.build", ["--out", "_site"])
end

conn
end
Expand Down
2 changes: 1 addition & 1 deletion lib/tableau_dev_server/server.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ defmodule TableauDevServer.Server do
@moduledoc false
def child_spec(_) do
Supervisor.child_spec(
{Bandit, scheme: :http, plug: Tableau.Router, port: 4999},
{Bandit, scheme: :http, plug: TableauDevServer.Router, port: 4999},
[]
)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/tableau_dev_server/server_supervisor.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ defmodule TableauDevServer.ServerSupervisor do
if Application.get_env(:tableau, :server) do
children = [
WebDevUtils.FileSystem,
Tableau.Server,
TableauDevServer.Server,
WebDevUtils.CodeReloader
]

Expand Down
12 changes: 6 additions & 6 deletions lib/tableau_dev_server/websocket.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@ defmodule TableauDevServer.Websocket do
@moduledoc false
require Logger

@reloader_opts Application.compile_env(:tableau, :reloader, patterns: [])

def init(_args) do
:ok = WebDevUtils.LiveReload.init()
{:ok, []}
{:ok, %{reloader: Application.get_env(:tableau, :reloader, patterns: [])}}
end

def handle_in({"subscribe", [opcode: :text]}, state) do
{:push, {:text, "subscribed"}, state}
end

def handle_info({:reload, _asset_type}, state) do
def handle_info(:reload, state) do
{:push, {:text, "reload"}, state}
end

def handle_info({:file_event, _watcher_pid, {_path, _event}} = file_event, state) do
WebDevUtils.LiveReload.reload!(file_event, patterns: @reloader_opts[:patterns])
def handle_info({:file_event, watcher_pid, {path, event}}, state) do
WebDevUtils.LiveReload.reload!({:file_event, watcher_pid, {Path.relative_to_cwd(path), event}},
patterns: state.reloader[:patterns]
)

{:ok, state}
end
Expand Down
3 changes: 1 addition & 2 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,8 @@ defmodule Tableau.MixProject do
{:mdex, "~> 0.2.0"},
{:plug_static_index_html, "~> 1.0"},
{:schematic, "~> 0.4"},
# {:schematic, path: "../schematic"},
{:tz, "~> 0.28.1"},
{:web_dev_utils, "~> 0.1"},
{:web_dev_utils, "~> 0.2"},
{:websock_adapter, "~> 0.5"},
{:xml_builder, "~> 2.1"},
{:yaml_elixir, "~> 2.9"},
Expand Down
4 changes: 2 additions & 2 deletions mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"date_time_parser": {:hex, :date_time_parser, "1.2.0", "3d5a816b91967f51e0f94dcb16a34b2cb780f22cd48931779e81d72f7d3eadb1", [:mix], [{:kday, "~> 1.0", [hex: :kday, repo: "hexpm", optional: false]}], "hexpm", "0cf09ada9f42c0b3bfba02dc0ea2e4b4d2f543d9d2bf99b831a29e6b4a4160e5"},
"earmark_parser": {:hex, :earmark_parser, "1.4.41", "ab34711c9dc6212dda44fcd20ecb87ac3f3fce6f0ca2f28d4a00e4154f8cd599", [:mix], [], "hexpm", "a81a04c7e34b6617c2792e291b5a2e57ab316365c2644ddc553bb9ed863ebefa"},
"ex_doc": {:hex, :ex_doc, "0.34.2", "13eedf3844ccdce25cfd837b99bea9ad92c4e511233199440488d217c92571e8", [:mix], [{:earmark_parser, "~> 1.4.39", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_c, ">= 0.1.0", [hex: :makeup_c, repo: "hexpm", optional: true]}, {:makeup_elixir, "~> 0.14 or ~> 1.0", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1 or ~> 1.0", [hex: :makeup_erlang, repo: "hexpm", optional: false]}, {:makeup_html, ">= 0.1.0", [hex: :makeup_html, repo: "hexpm", optional: true]}], "hexpm", "5ce5f16b41208a50106afed3de6a2ed34f4acfd65715b82a0b84b49d995f95c1"},
"file_system": {:hex, :file_system, "0.2.10", "fb082005a9cd1711c05b5248710f8826b02d7d1784e7c3451f9c1231d4fc162d", [:mix], [], "hexpm", "41195edbfb562a593726eda3b3e8b103a309b733ad25f3d642ba49696bf715dc"},
"file_system": {:hex, :file_system, "1.0.1", "79e8ceaddb0416f8b8cd02a0127bdbababe7bf4a23d2a395b983c1f8b3f73edd", [:mix], [], "hexpm", "4414d1f38863ddf9120720cd976fce5bdde8e91d8283353f0e31850fa89feb9e"},
"floki": {:hex, :floki, "0.36.2", "a7da0193538c93f937714a6704369711998a51a6164a222d710ebd54020aa7a3", [:mix], [], "hexpm", "a8766c0bc92f074e5cb36c4f9961982eda84c5d2b8e979ca67f5c268ec8ed580"},
"hpax": {:hex, :hpax, "1.0.0", "28dcf54509fe2152a3d040e4e3df5b265dcb6cb532029ecbacf4ce52caea3fd2", [:mix], [], "hexpm", "7f1314731d711e2ca5fdc7fd361296593fc2542570b3105595bb0bc6d0fad601"},
"html_entities": {:hex, :html_entities, "0.5.2", "9e47e70598da7de2a9ff6af8758399251db6dbb7eebe2b013f2bbd2515895c3c", [:mix], [], "hexpm", "c53ba390403485615623b9531e97696f076ed415e8d8058b1dbaa28181f4fdcc"},
Expand All @@ -25,7 +25,7 @@
"telemetry": {:hex, :telemetry, "1.3.0", "fedebbae410d715cf8e7062c96a1ef32ec22e764197f70cda73d82778d61e7a2", [:rebar3], [], "hexpm", "7015fc8919dbe63764f4b4b87a95b7c0996bd539e0d499be6ec9d7f3875b79e6"},
"thousand_island": {:hex, :thousand_island, "1.3.5", "6022b6338f1635b3d32406ff98d68b843ba73b3aa95cfc27154223244f3a6ca5", [:mix], [{:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "2be6954916fdfe4756af3239fb6b6d75d0b8063b5df03ba76fd8a4c87849e180"},
"tz": {:hex, :tz, "0.28.1", "717f5ffddfd1e475e2a233e221dc0b4b76c35c4b3650b060c8e3ba29dd6632e9", [:mix], [{:castore, "~> 0.1 or ~> 1.0", [hex: :castore, repo: "hexpm", optional: true]}, {:mint, "~> 1.6", [hex: :mint, repo: "hexpm", optional: true]}], "hexpm", "bfdca1aa1902643c6c43b77c1fb0cb3d744fd2f09a8a98405468afdee0848c8a"},
"web_dev_utils": {:hex, :web_dev_utils, "0.1.0", "0c41285667b4c9944eaa2c3189f22ec3a915c349c4b879b5ae023e8ca0824657", [:mix], [{:file_system, "~> 0.2", [hex: :file_system, repo: "hexpm", optional: false]}], "hexpm", "af82e1723fe76c09d817a9a9baf85160f7ed572cb4af854194d3f7609ae92f10"},
"web_dev_utils": {:hex, :web_dev_utils, "0.2.0", "3bcd109d1ac18445d06db095d5cfdca5de7586022641c0b09b0702788b8e4ea8", [:mix], [{:file_system, "~> 1.0", [hex: :file_system, repo: "hexpm", optional: false]}], "hexpm", "595e9bd35440ea2add0156ae9e68e578d986805d801dacf22b13067ca48980ed"},
"websock": {:hex, :websock, "0.5.3", "2f69a6ebe810328555b6fe5c831a851f485e303a7c8ce6c5f675abeb20ebdadc", [:mix], [], "hexpm", "6105453d7fac22c712ad66fab1d45abdf049868f253cf719b625151460b8b453"},
"websock_adapter": {:hex, :websock_adapter, "0.5.7", "65fa74042530064ef0570b75b43f5c49bb8b235d6515671b3d250022cb8a1f9e", [:mix], [{:bandit, ">= 0.6.0", [hex: :bandit, repo: "hexpm", optional: true]}, {:plug, "~> 1.14", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 2.6", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:websock, "~> 0.5", [hex: :websock, repo: "hexpm", optional: false]}], "hexpm", "d0f478ee64deddfec64b800673fd6e0c8888b079d9f3444dd96d2a98383bdbd1"},
"xml_builder": {:hex, :xml_builder, "2.3.0", "69d214c6ad41ae1300b36acff4367551cdfd9dc1b860affc16e103c6b1589053", [:mix], [], "hexpm", "972ec33346a225cd5acd14ab23d4e79042bd37cb904e07e24cd06992dde1a0ed"},
Expand Down