Skip to content

Commit

Permalink
Better caching
Browse files Browse the repository at this point in the history
  • Loading branch information
ankane committed Feb 27, 2018
1 parent 364f40d commit ead7ea6
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/ahoy/database_store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ def track_visit(data)
@visit = visit_model.create!(slice_data(visit_model, data))
rescue => e
raise e unless unique_exception?(e)
@visit = nil
remove_instance_variable(:@visit)
end

def track_event(data)
Expand Down Expand Up @@ -46,7 +46,10 @@ def authenticate(_)
end

def visit
@visit ||= visit_model.where(visit_token: ahoy.visit_token).first if ahoy.visit_token
unless defined?(@visit)
@visit = visit_model.where(visit_token: ahoy.visit_token).first if ahoy.visit_token
end
@visit
end

# if we don't have a visit, let's try to create one first
Expand Down

0 comments on commit ead7ea6

Please sign in to comment.