Always sort occupied date ranges in Imported.clamp_dates/3 (#4018)

This commit is contained in:
Adrian Gruntkowski 2024-04-18 11:15:51 +02:00 committed by GitHub
parent b373c36dcc
commit 9849743407
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 24 additions and 0 deletions

View File

@ -187,6 +187,7 @@ defmodule Plausible.Imported do
|> Imported.list_all_imports(Imported.SiteImport.completed())
|> Enum.reject(&(Date.diff(&1.end_date, &1.start_date) < 2))
|> Enum.map(&Date.range(&1.start_date, &1.end_date))
|> Enum.sort_by(& &1.first, Date)
end
@spec get_cutoff_date(Site.t()) :: Date.t()

View File

@ -164,6 +164,29 @@ defmodule Plausible.ImportedTest do
Imported.clamp_dates(site, ~D[2019-03-21], ~D[2024-01-12])
end
test "does not depend on the order of insertion of site imports (regression fix)" do
site = insert(:site)
_existing_import1 =
insert(:site_import,
site: site,
start_date: ~D[2020-10-14],
end_date: ~D[2024-04-01],
status: :completed
)
_existing_import2 =
insert(:site_import,
site: site,
start_date: ~D[2012-01-18],
end_date: ~D[2018-03-09],
status: :completed
)
assert {:ok, ~D[2018-03-09], ~D[2020-10-14]} =
Imported.clamp_dates(site, ~D[2012-01-18], ~D[2018-03-09])
end
test "does not alter the dates when there are no imports and no native stats" do
site = insert(:site)