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
This commit is contained in:
taitus
2025-05-30 12:32:12 +02:00
parent c8c7580e25
commit f45f5fe98f
3 changed files with 4 additions and 13 deletions

View File

@@ -58,7 +58,6 @@ gem "sprockets-rails", "~> 3.5.2", require: "sprockets/railtie"
gem "turbolinks", "~> 5.2.1" gem "turbolinks", "~> 5.2.1"
gem "turnout", "~> 2.5.0" gem "turnout", "~> 2.5.0"
gem "uglifier", "~> 4.2.1" gem "uglifier", "~> 4.2.1"
gem "uuidtools", "~> 2.2.0"
gem "view_component", "~> 3.23.1" gem "view_component", "~> 3.23.1"
gem "whenever", "~> 1.0.0", require: false gem "whenever", "~> 1.0.0", require: false
gem "wicked_pdf", "~> 2.8.2" gem "wicked_pdf", "~> 2.8.2"

View File

@@ -703,7 +703,6 @@ GEM
unicode-emoji (~> 4.0, >= 4.0.4) unicode-emoji (~> 4.0, >= 4.0.4)
unicode-emoji (4.0.4) unicode-emoji (4.0.4)
uri (1.0.3) uri (1.0.3)
uuidtools (2.2.0)
version_gem (1.1.8) version_gem (1.1.8)
view_component (3.23.1) view_component (3.23.1)
activesupport (>= 5.2.0, < 8.1) activesupport (>= 5.2.0, < 8.1)
@@ -834,7 +833,6 @@ DEPENDENCIES
turbolinks (~> 5.2.1) turbolinks (~> 5.2.1)
turnout (~> 2.5.0) turnout (~> 2.5.0)
uglifier (~> 4.2.1) uglifier (~> 4.2.1)
uuidtools (~> 2.2.0)
view_component (~> 3.23.1) view_component (~> 3.23.1)
web-console (~> 4.2.1) web-console (~> 4.2.1)
whenever (~> 1.0.0) whenever (~> 1.0.0)

View File

@@ -8,17 +8,17 @@ class Ahoy::Store < Ahoy::DatabaseStore
end end
def track_visit(data) def track_visit(data)
data[:id] = ensure_uuid(data.delete(:visit_token)) data[:id] = ahoy.visit_token
data[:visitor_id] = ensure_uuid(data.delete(:visitor_token)) data[:visitor_id] = ahoy.visitor_token
super(data) super(data)
end end
def visit def visit
unless defined?(@visit) unless defined?(@visit)
if ahoy.send(:existing_visit_token) || ahoy.instance_variable_get(:@visit_token) 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 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..) .where(started_at: Ahoy.visit_duration.ago..)
.order(started_at: :desc) .order(started_at: :desc)
.first .first
@@ -34,12 +34,6 @@ class Ahoy::Store < Ahoy::DatabaseStore
Visit Visit
end 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? def exclude?
false false
end end