mirror of
https://github.com/plausible/analytics.git
synced 2024-12-22 17:11:36 +03:00
Always sort occupied date ranges in Imported.clamp_dates/3
(#4018)
This commit is contained in:
parent
b373c36dcc
commit
9849743407
@ -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()
|
||||
|
@ -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)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user