defmodule ElixirDashboardWeb.PerformanceLive.Queries do @moduledoc """ Demo app wrapper - delegates to the library LiveView. """ use ElixirDashboardWeb, :live_view alias ElixirDashboard.PerformanceMonitor.Store @impl true def mount(_params, _session, socket) do if connected?(socket) do # Refresh data every 5 seconds :timer.send_interval(5000, self(), :refresh) end queries = Store.get_slow_queries() {:ok, assign(socket, :queries, queries)} end @impl true def handle_info(:refresh, socket) do queries = Store.get_slow_queries() {:noreply, assign(socket, :queries, queries)} end @impl true def handle_event("clear", _params, socket) do Store.clear_all() {:noreply, assign(socket, :queries, [])} end @impl true def render(assigns) do ~H"""

Slow SQL Queries

Showing the 100 slowest queries recorded since the server started (threshold: 50ms).

No slow queries recorded yet. Start making database requests to see data.

0} class="space-y-4">
<%= query.duration_ms %>ms <%= format_timestamp(query.timestamp) %>

Endpoint: <%= query.endpoint_path %>

SQL Query:

<%= query.query %>
0} class="mt-3 bg-blue-50 rounded-md p-3 border border-blue-200" >

Parameters:

<%= inspect(query.params, pretty: true) %>
""" end defp format_timestamp(milli) do milli |> DateTime.from_unix!(:millisecond) |> Calendar.strftime("%Y-%m-%d %H:%M:%S") end defp duration_color(ms) when ms > 500, do: "text-red-600" defp duration_color(ms) when ms > 200, do: "text-orange-600" defp duration_color(ms) when ms > 100, do: "text-yellow-600" defp duration_color(_), do: "text-green-600" end