Skip to content

Commit

Permalink
counters, tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
aqeelvn committed Jun 12, 2017
1 parent d6d365c commit bcac917
Show file tree
Hide file tree
Showing 13 changed files with 60 additions and 4 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ gem 'monban'
gem 'kaminari'
gem 'jquery-rails'
gem "paperclip", "~> 5.0.0"
gem 'resque'

group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
Expand All @@ -50,6 +51,7 @@ group :development do
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
gem 'foreman'
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
Expand Down
24 changes: 24 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ GEM
erubi (1.6.0)
execjs (2.7.0)
ffi (1.9.18)
foreman (0.84.0)
thor (~> 0.19.1)
globalid (0.4.0)
activesupport (>= 4.2.0)
i18n (0.8.4)
Expand Down Expand Up @@ -100,7 +102,9 @@ GEM
warden
monban-generators (1.0.0)
monban (>= 0.0.12)
mono_logger (1.1.0)
multi_json (1.12.1)
mustermann (1.0.0)
mysql2 (0.4.6)
nio4r (2.1.0)
nokogiri (1.7.2)
Expand All @@ -113,6 +117,8 @@ GEM
mimemagic (~> 0.3.0)
puma (3.9.1)
rack (2.0.3)
rack-protection (2.0.0)
rack
rack-test (0.6.3)
rack (>= 1.0)
rails (5.1.1)
Expand Down Expand Up @@ -142,6 +148,15 @@ GEM
rb-fsevent (0.9.8)
rb-inotify (0.9.8)
ffi (>= 0.5.0)
redis (3.3.3)
redis-namespace (1.5.3)
redis (~> 3.0, >= 3.0.4)
resque (1.27.4)
mono_logger (~> 1.0)
multi_json (~> 1.0)
redis-namespace (~> 1.3)
sinatra (>= 0.9.2)
vegas (~> 0.1.2)
ruby_dep (1.5.0)
sass (3.4.24)
sass-rails (5.0.6)
Expand All @@ -150,6 +165,11 @@ GEM
sprockets (>= 2.8, < 4.0)
sprockets-rails (>= 2.0, < 4.0)
tilt (>= 1.1, < 3)
sinatra (2.0.0)
mustermann (~> 1.0)
rack (~> 2.0)
rack-protection (= 2.0.0)
tilt (~> 2.0)
spring (2.0.2)
activesupport (>= 4.2)
spring-watcher-listen (2.0.1)
Expand All @@ -172,6 +192,8 @@ GEM
thread_safe (~> 0.1)
uglifier (3.2.0)
execjs (>= 0.3.0, < 3)
vegas (0.1.11)
rack (>= 1.0.0)
warden (1.2.7)
rack (>= 1.0)
web-console (3.5.1)
Expand All @@ -189,6 +211,7 @@ PLATFORMS
DEPENDENCIES
byebug
coffee-rails (~> 4.2)
foreman
jbuilder (~> 2.5)
jquery-rails
kaminari
Expand All @@ -199,6 +222,7 @@ DEPENDENCIES
paperclip (~> 5.0.0)
puma (~> 3.7)
rails (~> 5.1.1)
resque
sass-rails (~> 5.0)
spring
spring-watcher-listen (~> 2.0.0)
Expand Down
2 changes: 2 additions & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
web: bundle exec puma -C config/puma.rb
background: QUEUE=* COUNT=1 bundle exec rake environment resque:workers
2 changes: 2 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.

require_relative 'config/application'
require 'resque/tasks'

Rails.application.load_tasks
task 'resque:setup' => :environment
5 changes: 4 additions & 1 deletion app/jobs/publish_activity_job.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
class PublishActivityJob < ApplicationJob
queue_as :default
rescue_from 'ActiveJob::DeserializationError', with: ->{}

def perform(user:, action:, target:)
UserActivityPublisher.new(user: user, action: action, target: target).run(delay: false)
UserActivityPublisher.
new(user: user, action: action, target: target).
run(delay: false)
end
end
2 changes: 1 addition & 1 deletion app/models/bookmark.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class Bookmark < ApplicationRecord
validates :recipe_id, uniqueness: {scope: :user_id}
belongs_to :user
belongs_to :recipe
belongs_to :recipe, counter_cache: true
end
2 changes: 1 addition & 1 deletion app/models/comment.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class Comment < ApplicationRecord
belongs_to :user
belongs_to :recipe
belongs_to :recipe, counter_cache: true
end
4 changes: 4 additions & 0 deletions app/views/recipes/_recipe.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
</div>
<div class="part details">
<%= link_to recipe.title, recipe %>
<div>
<span>Comments: <%= recipe.comments_count %></span>
<span>Bookmarks: <%= recipe.bookmarks_count %></span>
</div>
<div>
<%= recipe.description %>
</div>
Expand Down
2 changes: 2 additions & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,7 @@ class Application < Rails::Application

# Don't generate system test files.
config.generators.system_tests = nil

config.active_job.queue_adapter = :resque
end
end
5 changes: 5 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require "monban/constraints/signed_in"
require "monban/constraints/signed_out"
require "resque/server"

Rails.application.routes.draw do
constraints Monban::Constraints::SignedOut.new do
Expand All @@ -10,6 +11,10 @@
root to: "dashboards#show"
end

constraints ->(_request) { Rails.env.development? } do
mount Resque::Server, at: '/jobs'
end

resource :search, only: %i(show)

resources :recipes, only: %i(show) do
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20170612043506_add_comments_count_to_recipes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddCommentsCountToRecipes < ActiveRecord::Migration[5.1]
def change
add_column :recipes, :comments_count, :integer, null: false, default: 0
end
end
5 changes: 5 additions & 0 deletions db/migrate/20170612045035_add_bookmarks_count_to_recipe.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddBookmarksCountToRecipe < ActiveRecord::Migration[5.1]
def change
add_column :recipes, :bookmarks_count, :integer, null: false, default: 0
end
end
4 changes: 3 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20170609064339) do
ActiveRecord::Schema.define(version: 20170612045035) do

create_table "bookmarks", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
t.bigint "user_id"
Expand Down Expand Up @@ -80,6 +80,8 @@
t.string "cover_image_content_type"
t.integer "cover_image_file_size"
t.datetime "cover_image_updated_at"
t.integer "comments_count", default: 0, null: false
t.integer "bookmarks_count", default: 0, null: false
t.index ["user_id"], name: "index_recipes_on_user_id"
end

Expand Down

0 comments on commit bcac917

Please sign in to comment.