Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

fix: remove duplicate visits calculation in dashboard controller (#12725)

Vladimir Raileana405633e5932
diff --git a/admin/app/controllers/spree/admin/dashboard_controller.rb b/admin/app/controllers/spree/admin/dashboard_controller.rb
index 4b0ff48a7a..f7e02b07d6 100644
--- a/admin/app/controllers/spree/admin/dashboard_controller.rb
+++ b/admin/app/controllers/spree/admin/dashboard_controller.rb
@@ -117,9 +117,11 @@ module Spree
@audience_growth_rate = calc_growth_rate(@audience_total, previous_audience_total)
@audience = if same_day?
- @audience_scope.group_by_hour(:created_at, range: analytics_time_range, time_zone: current_store.preferred_timezone, default_value: 0)
+ @audience_scope.group_by_hour(:created_at, range: analytics_time_range, time_zone: current_store.preferred_timezone,
+ default_value: 0)
else
- @audience_scope.group_by_day(:created_at, range: analytics_time_range, time_zone: current_store.preferred_timezone, default_value: 0)
+ @audience_scope.group_by_day(:created_at, range: analytics_time_range, time_zone: current_store.preferred_timezone,
+ default_value: 0)
end
return unless defined?(Ahoy)
@@ -129,15 +131,12 @@ module Spree
previous_visits_total = Ahoy::Visit.where(started_at: previous_analytics_time_range).count
@visits_growth_rate = calc_growth_rate(@visits_total, previous_visits_total)
- @visits_scope = Ahoy::Visit.where(started_at: analytics_time_range)
- @visits_total = @visits_scope.count
- previous_visits_total = Ahoy::Visit.where(started_at: previous_analytics_time_range).count
- @visits_growth_rate = calc_growth_rate(@visits_total, previous_visits_total)
-
@visits = if same_day?
- @visits_scope.group_by_hour(:started_at, range: analytics_time_range, time_zone: current_store.preferred_timezone, default_value: 0)
+ @visits_scope.group_by_hour(:started_at, range: analytics_time_range, time_zone: current_store.preferred_timezone,
+ default_value: 0)
else
- @visits_scope.group_by_day(:started_at, range: analytics_time_range, time_zone: current_store.preferred_timezone, default_value: 0)
+ @visits_scope.group_by_day(:started_at, range: analytics_time_range, time_zone: current_store.preferred_timezone,
+ default_value: 0)
end
@top_landing_pages = @visits_scope.where.not(landing_page_title: [nil, '']).top(:landing_page_title, 10)
@@ -146,8 +145,8 @@ module Spree
)
@top_locations = @visits_scope.top(:country, 10)
@top_devices = @visits_scope.group(:device_type).count.transform_keys do |device|
- device.nil? ? 'N/A' : device
- end.map { |series| [series.first, (series.second.to_f / @visits_scope.count) * 100] }
+ device.nil? ? 'N/A' : device
+ end.map { |series| [series.first, (series.second.to_f / @visits_scope.count) * 100] }
end
end
end