Open source, privacy-first web analytics. Lightweight, cookie-free Google Analytics alternative. Self-hosted or cloud.
TypeScript analyticsanalytics-dashboardclickhouseelixirgoogle-analyticsmarketingopen-source-analyticsphoenixplausible-analyticspostgresqlprivacyprivacy-friendlyself-hostedsimple-analyticsstatisticstailwindcssweb-analyticswebsite-analyticswebsite-statswebsite-tracking
Always sort occupied date ranges in `Imported.clamp_dates/3` (#4018)
Adrian Gruntkowski984974340746
diff --git a/lib/plausible/imported.ex b/lib/plausible/imported.exindex b21aac504d..100667e480 100644--- a/lib/plausible/imported.ex+++ b/lib/plausible/imported.ex@@ -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()diff --git a/test/plausible/imported_test.exs b/test/plausible/imported_test.exsindex c0d994f25e..37b989795a 100644--- a/test/plausible/imported_test.exs+++ b/test/plausible/imported_test.exs@@ -164,6 +164,29 @@ defmodule Plausible.ImportedTest doImported.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" dosite = insert(:site)