mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 21:03:43 +08:00
a method called "adding_user_record" is annoying me. 5 lines of code replaced with 2
This commit is contained in:
parent
ea8d69fbd6
commit
5273657537
|
@ -287,18 +287,14 @@ class User < ActiveRecord::Base
|
||||||
user_visits.where(visited_at: date).first
|
user_visits.where(visited_at: date).first
|
||||||
end
|
end
|
||||||
|
|
||||||
def adding_visit_record(date)
|
|
||||||
user_visits.create!(visited_at: date)
|
|
||||||
end
|
|
||||||
|
|
||||||
def update_visit_record!(date)
|
def update_visit_record!(date)
|
||||||
unless seen_before?
|
unless seen_before?
|
||||||
adding_visit_record(date)
|
user_visits.create!(visited_at: date)
|
||||||
update_column(:days_visited, 1)
|
update_column(:days_visited, 1)
|
||||||
end
|
end
|
||||||
|
|
||||||
unless seen?(date) || has_visit_record?(date)
|
unless seen?(date) || has_visit_record?(date)
|
||||||
adding_visit_record(date)
|
user_visits.create!(visited_at: date)
|
||||||
User.update_all('days_visited = days_visited + 1', id: self.id)
|
User.update_all('days_visited = days_visited + 1', id: self.id)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user