From f45f5fe98fedf773699897e0d0200e52d9625455 Mon Sep 17 00:00:00 2001 From: taitus Date: Fri, 30 May 2025 12:32:12 +0200 Subject: [PATCH] Remove Ahoy ensure_uuid logic and uuidtools dependency Ahoy 2.0.0 [1] introduced automatic UUID generation for visit_token and visitor_token. As a result, the custom ensure_uuid method is no longer needed and can be safely removed from the initializer. Since we aren't manually generating UUIDs anymore, we no longer need the uuidtools dependency. [1] https://github.com/ankane/ahoy/blob/v2.0.0/README.md#token-generation --- Gemfile | 1 - Gemfile.lock | 2 -- config/initializers/ahoy.rb | 14 ++++---------- 3 files changed, 4 insertions(+), 13 deletions(-) diff --git a/Gemfile b/Gemfile index 21cb3e9fb..be8b56004 100644 --- a/Gemfile +++ b/Gemfile @@ -58,7 +58,6 @@ gem "sprockets-rails", "~> 3.5.2", require: "sprockets/railtie" gem "turbolinks", "~> 5.2.1" gem "turnout", "~> 2.5.0" gem "uglifier", "~> 4.2.1" -gem "uuidtools", "~> 2.2.0" gem "view_component", "~> 3.23.1" gem "whenever", "~> 1.0.0", require: false gem "wicked_pdf", "~> 2.8.2" diff --git a/Gemfile.lock b/Gemfile.lock index e42e26a80..c775f833e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -703,7 +703,6 @@ GEM unicode-emoji (~> 4.0, >= 4.0.4) unicode-emoji (4.0.4) uri (1.0.3) - uuidtools (2.2.0) version_gem (1.1.8) view_component (3.23.1) activesupport (>= 5.2.0, < 8.1) @@ -834,7 +833,6 @@ DEPENDENCIES turbolinks (~> 5.2.1) turnout (~> 2.5.0) uglifier (~> 4.2.1) - uuidtools (~> 2.2.0) view_component (~> 3.23.1) web-console (~> 4.2.1) whenever (~> 1.0.0) diff --git a/config/initializers/ahoy.rb b/config/initializers/ahoy.rb index 7184935bc..b4944d215 100644 --- a/config/initializers/ahoy.rb +++ b/config/initializers/ahoy.rb @@ -8,17 +8,17 @@ class Ahoy::Store < Ahoy::DatabaseStore end def track_visit(data) - data[:id] = ensure_uuid(data.delete(:visit_token)) - data[:visitor_id] = ensure_uuid(data.delete(:visitor_token)) + data[:id] = ahoy.visit_token + data[:visitor_id] = ahoy.visitor_token super(data) end def visit unless defined?(@visit) if ahoy.send(:existing_visit_token) || ahoy.instance_variable_get(:@visit_token) - @visit = visit_model.where(id: ensure_uuid(ahoy.visit_token)).take if ahoy.visit_token + @visit = visit_model.where(id: ahoy.visit_token).take if ahoy.visit_token elsif !Ahoy.cookies? && ahoy.visitor_token - @visit = visit_model.where(visitor_id: ensure_uuid(ahoy.visitor_token)) + @visit = visit_model.where(visitor_id: ahoy.visitor_token) .where(started_at: Ahoy.visit_duration.ago..) .order(started_at: :desc) .first @@ -34,12 +34,6 @@ class Ahoy::Store < Ahoy::DatabaseStore Visit end - def ensure_uuid(id) - UUIDTools::UUID.parse(id).to_s - rescue - UUIDTools::UUID.sha1_create(UUIDTools::UUID.parse(Ahoy::Tracker::UUID_NAMESPACE), id).to_s - end - def exclude? false end