mirror of
https://github.com/plausible/analytics.git
synced 2024-11-23 20:13:31 +03:00
Fix realtime dashboard
This commit is contained in:
parent
bea26f0707
commit
0fe053e106
@ -41,7 +41,7 @@ defmodule Plausible.Stats.Query do
|
||||
date = today(tz)
|
||||
|
||||
%__MODULE__{
|
||||
period: "30m",
|
||||
period: "realtime",
|
||||
interval: "minute",
|
||||
date_range: Date.range(date, date),
|
||||
filters: parse_filters(params),
|
||||
|
@ -15,7 +15,14 @@ defmodule PlausibleWeb.Api.StatsController do
|
||||
_ -> query
|
||||
end
|
||||
|
||||
timeseries = Task.async(fn -> Stats.timeseries(site, query, ["visitors"]) end)
|
||||
timeseries_query =
|
||||
if query.period == "realtime" do
|
||||
%Query{query | period: "30m"}
|
||||
else
|
||||
query
|
||||
end
|
||||
|
||||
timeseries = Task.async(fn -> Stats.timeseries(site, timeseries_query, ["visitors"]) end)
|
||||
{top_stats, sample_percent} = fetch_top_stats(site, query)
|
||||
|
||||
timeseries_result = Task.await(timeseries)
|
||||
@ -62,11 +69,13 @@ defmodule PlausibleWeb.Api.StatsController do
|
||||
end
|
||||
end
|
||||
|
||||
defp fetch_top_stats(site, %Query{period: "30m"} = query) do
|
||||
defp fetch_top_stats(site, %Query{period: "realtime"} = query) do
|
||||
query_30m = %Query{query | period: "30m"}
|
||||
|
||||
%{
|
||||
"visitors" => %{"value" => visitors},
|
||||
"pageviews" => %{"value" => pageviews}
|
||||
} = Stats.aggregate(site, query, ["visitors", "pageviews"])
|
||||
} = Stats.aggregate(site, query_30m, ["visitors", "pageviews"])
|
||||
|
||||
stats = [
|
||||
%{
|
||||
@ -482,6 +491,14 @@ defmodule PlausibleWeb.Api.StatsController do
|
||||
def conversions(conn, params) do
|
||||
site = conn.assigns[:site]
|
||||
query = Query.from(site.timezone, params) |> Filters.add_prefix()
|
||||
|
||||
query =
|
||||
if query.period == "realtime" do
|
||||
%Query{query | period: "30m"}
|
||||
else
|
||||
query
|
||||
end
|
||||
|
||||
pagination = parse_pagination(params)
|
||||
|
||||
total_q = Query.remove_goal(query)
|
||||
|
@ -25,7 +25,7 @@ defmodule Plausible.Stats.QueryTest do
|
||||
|
||||
assert q.date_range.first == Timex.today()
|
||||
assert q.date_range.last == Timex.today()
|
||||
assert q.period == "30m"
|
||||
assert q.period == "realtime"
|
||||
end
|
||||
|
||||
test "parses month format" do
|
||||
|
Loading…
Reference in New Issue
Block a user