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.
This commit is contained in:
Vini Brasil 2023-06-19 11:02:31 +01:00 committed by GitHub
parent f0bdf872b5
commit 5012e0c0ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 1 deletions

View File

@ -32,6 +32,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`

View File

@ -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

View File

@ -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]),