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:
1
Gemfile
1
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"
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user