Skip to content

Commit

Permalink
not break shit
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxime Bedard committed Mar 26, 2017
1 parent 733ff5d commit 2719d23
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
3 changes: 1 addition & 2 deletions app/controllers/videos_controller.rb
Expand Up @@ -6,7 +6,7 @@ def index

def show
@video = Video.find(params[:id])
@feedback = Ordinateur.redis.hget("likes:#{current_user.id}")
@video.increment_view_count(current_user)
end

def new
Expand All @@ -20,7 +20,6 @@ def create
end

def like
Ordinateur.redis.hset("likes:#{current_user.id}", !!params[:feedback])
end

def update
Expand Down
9 changes: 6 additions & 3 deletions app/models/video.rb
Expand Up @@ -7,8 +7,11 @@ def public_url
""
end

def views_count
# shitty but works
Ordinateur.redis.increment("views:#{@video.id}:#{current_user.id}")
def view_count
@view_count ||= Ordinateur.redis.hgetall("views:#{id}").sum
end

def increment_view_count(current_user)
Ordinateur.redis.incr("views:#{id}:#{current_user.id}")
end
end
3 changes: 1 addition & 2 deletions app/views/videos/show.html.erb
Expand Up @@ -7,8 +7,7 @@
<%= link_to nil, "👍" %>
<%= link_to nil, "👎" %>

Views: <%= @video.views_count %>
Views: <%= @video.view_count %>
<%= render(@video.comments) %>
<%= render "add_comment", comment: Comment.new %>
</div>

0 comments on commit 2719d23

Please sign in to comment.