Ignore unknown country in imported data (#2247)

pull/2252/head
Uku Taht 4 years ago committed by GitHub
parent df76cd2c8c
commit 669091f2ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -179,7 +179,7 @@ defmodule Plausible.Stats.Imported do
|> select_merge([i], %{exit_page: i.exit_page, visits: sum(i.exits)})
:country ->
imported_q |> select_merge([i], %{country: i.country})
imported_q |> where([i], i.country != "ZZ") |> select_merge([i], %{country: i.country})
:region ->
imported_q |> where([i], i.region != "") |> select_merge([i], %{region: i.region})

@ -68,9 +68,12 @@ defmodule PlausibleWeb.Api.StatsController.CountriesTest do
end
test "ignores unknown country code ZZ", %{conn: conn, site: site} do
populate_stats(site, [build(:pageview, country_code: "ZZ")])
populate_stats(site, [
build(:pageview, country_code: "ZZ"),
build(:imported_locations, country: "ZZ")
])
conn = get(conn, "/api/stats/#{site.domain}/countries?period=day")
conn = get(conn, "/api/stats/#{site.domain}/countries?period=day&with_imported=true")
assert json_response(conn, 200) == []
end

Loading…
Cancel
Save