Clear stats_start_date after clearing GA stats (#2370)

This commit fixes a bug where users clearing one import and trying to
re-import would get invalid import date ranges. This was caused because
the stats_start_date field was not updated to nil after clearing
imported stats, as this field defines the end date of the import.
pull/2375/head
Vinicius Brasil 4 years ago committed by GitHub
parent b883d44697
commit a86d9697ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -23,7 +23,8 @@ defmodule Plausible.Purge do
@spec delete_imported_stats!(Plausible.Site.t()) :: :ok
@doc """
Deletes imported stats from Google Analytics.
Deletes imported stats from Google Analytics, and clears the
`stats_start_date` field.
"""
def delete_imported_stats!(site) do
Enum.each(Plausible.Imported.tables(), fn table ->
@ -31,6 +32,8 @@ defmodule Plausible.Purge do
Ecto.Adapters.SQL.query!(Plausible.ClickhouseRepo, sql, [site.id])
end)
clear_stats_start_date!(site)
:ok
end

@ -45,9 +45,9 @@ defmodule Plausible.PurgeTest do
end)
end
test "delete_imported_stats!/1 does not reset stats_start_date", %{site: site} do
test "delete_imported_stats!/1 resets stats_start_date", %{site: site} do
assert :ok == Plausible.Purge.delete_imported_stats!(site)
assert %Date{} = site.stats_start_date
assert %Plausible.Site{stats_start_date: nil} = Plausible.Repo.reload(site)
end
test "delete_native_stats!/1 deletes native stats", %{site: site} do

Loading…
Cancel
Save