Add map of descriptions for built-in services to reduce startup time #4

Open
opened 2024-05-23 12:47:14 +02:00 by hiway · 0 comments
Owner

Freedive loads services at startup

state =
state
|> Map.put(:services, list_services!())

def list_services!() do
all_service_names = all_service_names()
enabled_service_names = enabled_service_names()
all_service_names
|> Enum.map(fn name -> service_details!(name, Enum.member?(enabled_service_names, name)) end)
|> Enum.into(%{}, &{&1[:name], &1})
end

def all_service_names() do
case execute(@service_bin, ["-l"]) do
{:ok, stdout} ->
stdout
|> String.split("\n")
|> Enum.map(&String.trim/1)
|> Enum.reject(&Enum.member?(@skip_service_names, &1))

def enabled_service_names() do
case execute(@service_bin, ["-e"]) do
{:ok, stdout} ->
stdout
|> String.split("\n")
|> Enum.map(&String.trim/1)
|> Enum.map(&Path.basename/1)

This can take while if many services are enabled and running. Freedive only loads descriptions for enabled services to prevent long startup times. Descriptions for built-in services can be added as a static map to speed up initial loading time and enusre descriptions are available for all services, and can be displayed in the service list view on tablet/desktop.

Freedive loads services at startup https://brew.bsd.cafe/hiway/freedive/src/commit/d2e31dbbbd220fcaef4f1ef027bf6ca151f12d99/lib/freedive/api/service/server.ex#L79-L81 https://brew.bsd.cafe/hiway/freedive/src/commit/d2e31dbbbd220fcaef4f1ef027bf6ca151f12d99/lib/freedive/api/service/cli.ex#L12-L19 https://brew.bsd.cafe/hiway/freedive/src/commit/d2e31dbbbd220fcaef4f1ef027bf6ca151f12d99/lib/freedive/api/service/cli.ex#L31-L37 https://brew.bsd.cafe/hiway/freedive/src/commit/d2e31dbbbd220fcaef4f1ef027bf6ca151f12d99/lib/freedive/api/service/cli.ex#L45-L51 This can take while if many services are enabled and running. Freedive only loads descriptions for enabled services to prevent long startup times. Descriptions for built-in services can be added as a static map to speed up initial loading time and enusre descriptions are available for all services, and can be displayed in the service list view on tablet/desktop.
hiway changed title from Add map of built-in services to reduce startup time to Add map of descriptions for built-in services to reduce startup time 2024-05-23 12:49:37 +02:00
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: hiway/freedive#4
No description provided.