Update native stats start date when transferring (#2719)

This commit is contained in:
Uku Taht 2023-03-02 12:01:57 +02:00 committed by GitHub
parent 8f86036e57
commit f26ca7da9f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 1 deletions

View File

@ -87,6 +87,10 @@ defmodule Plausible.Site do
change(site, stats_start_date: val)
end
def set_native_stats_start_at(site, val) do
change(site, native_stats_start_at: val)
end
def start_import(site, start_date, end_date, imported_source, status \\ "importing") do
change(site,
imported_data: %{

View File

@ -96,7 +96,9 @@ defmodule Plausible.SiteAdmin do
start_date = Plausible.Stats.Clickhouse.pageview_start_date_local(from_site)
{:ok, _} =
Plausible.Site.set_stats_start_date(to_site, start_date)
to_site
|> Plausible.Site.set_stats_start_date(start_date)
|> Plausible.Site.set_native_stats_start_at(from_site.native_stats_start_at)
|> Repo.update()
:ok

View File

@ -62,6 +62,17 @@ defmodule Plausible.SiteAdminTest do
assert Repo.reload(to_site).stats_start_date == ~D[2022-01-01]
end
test "updates native_stats_start_date on based on the from_site record" do
from_site = insert(:site, native_stats_start_at: ~N[2022-01-01 01:00:00])
to_site = insert(:site)
populate_stats(from_site, [build(:pageview, timestamp: ~N[2022-01-01 13:21:00])])
SiteAdmin.transfer_data([from_site], %{"domain" => to_site.domain})
assert Repo.reload(to_site).native_stats_start_at == ~N[2022-01-01 01:00:00]
end
test "session_transfer_query" do
actual = SiteAdmin.session_transfer_query("from.com", "to.com")