Set with_imported=false in realtime mode (#3053)

This commit fixes a bug where timeseries queries - such as the main
graph - would fail with imported data in realtime mode. Realtime mode
`date` field is not actually a date, but minutes from now. This would
cause the imported tables join to fail with this error:

```
(Ch.Error Code: 53. DB::Exception: Can't infer common type for joined
columns: date: Int64 at left, s1.date: Date at right. There is no
supertype for types Int64, Date because some of them are
Date/Date32/DateTime/DateTime64 and some of them are not.
(TYPE_MISMATCH)
```

This commit removes imported data from realtime queries, as it doesn't
make sense to include it. Imported data does not have time precision,
and would only appear in the first day the data was imported anyways.
pull/3081/head
Vini Brasil 3 years ago committed by ruslandoga
parent dec7e7e824
commit 2ab8453a57

@ -31,6 +31,7 @@ All notable changes to this project will be documented in this file.
- Fix bug when combining goal and prop filters plausible/analytics#2654
- Fix broken favicons when domain includes a slash
- Fix bug when using multiple [wildcard goal filters](https://github.com/plausible/analytics/pull/3015)
- Fix a bug where realtime would fail with imported data
### Changed
- Treat page filter as entry page filter for `bounce_rate`

@ -235,6 +235,7 @@ defmodule Plausible.Stats.Query do
site.imported_data.status != "ok" -> false
Timex.after?(query.date_range.first, site.imported_data.end_date) -> false
Enum.any?(query.filters) -> false
query.period == "realtime" -> false
true -> requested?
end
end

@ -33,12 +33,29 @@ defmodule PlausibleWeb.Api.StatsController.MainGraphTest do
assert %{"plot" => plot} = json_response(conn, 200)
zeroes = Stream.repeatedly(fn -> 0 end) |> Stream.take(22) |> Enum.into([])
zeroes = List.duplicate(0, 22)
assert Enum.count(plot) == 24
assert plot == [1] ++ zeroes ++ [1]
end
test "returns empty plot with no native data and recently imported from ga in realtime graph",
%{conn: conn, site: site} do
populate_stats(site, [
build(:imported_visitors, date: Date.utc_today()),
build(:imported_visitors, date: Date.utc_today())
])
conn =
get(
conn,
"/api/stats/#{site.domain}/main-graph?period=realtime&with_imported=true"
)
zeroes = List.duplicate(0, 30)
assert %{"plot" => ^zeroes, "with_imported" => false} = json_response(conn, 200)
end
test "displays visitors for a day with imported data", %{conn: conn, site: site} do
populate_stats(site, [
build(:pageview, timestamp: ~N[2021-01-01 00:00:00]),

Loading…
Cancel
Save