Issues with queries
Opened this issue · 0 comments
project-orcon commented
It looks like the queries for the top sources, maps and devices sections are wrong - they should be counting unique visits but instead because of the left outer join to events they're counting views instead
Ahoy::Visit Count (0.8ms) SELECT COUNT(*) AS "count_all", "ahoy_visits"."country" AS "ahoy_visits_country" FROM "ahoy_visits" LEFT OUTER JOIN "ahoy_events" ON "ahoy_events"."visit_id" = "ahoy_visits"."id" WHERE ("ahoy_visits"."started_at" > '2024-08-10 04:56:47.803227' AND "ahoy_visits"."started_at" < '2024-09-09 04:56:47.803276') AND ("ahoy_events"."time" > '2024-08-10 04:56:47.803519' AND "ahoy_events"."time" < '2024-09-09 04:56:47.803567') GROUP BY "ahoy_visits"."country"
Ahoy::Visit Load (3.7ms) SELECT browser as label, count(browser) as count, sum(count(browser)) over() as total_count FROM "ahoy_visits" LEFT OUTER JOIN "ahoy_events" ON "ahoy_events"."visit_id" = "ahoy_visits"."id" WHERE ("ahoy_visits"."started_at" > '2024-08-10 04:56:47.801767' AND "ahoy_visits"."started_at" < '2024-09-09 04:56:47.801824') AND ("ahoy_events"."time" > '2024-08-10 04:56:47.802147' AND "ahoy_events"."time" < '2024-09-09 04:56:47.802194') GROUP BY "ahoy_visits"."browser" ORDER BY count(browser) desc LIMIT $1
this query AhoyCaptain.visit.joins(shared_context.join_sources) should have .distinct on it
also it it would be good in the UX if instead of displaying 'visitors' in each of these sections it displayed 'visits' & for top pages it displayed 'views'