trendable 1.2.0 → 1.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 0f3496ff5b5f317e0ac19af1fc510daebab600b9
4
- data.tar.gz: 235bff5831a602bf1417f74b8157a8ac609bb8b8
2
+ SHA256:
3
+ metadata.gz: 03460e66c631e8ed7144e8d6cf2ad7fe33535cfbd51e25709ee9ca45b2bec78a
4
+ data.tar.gz: 285845241d9f4699d93e5bb92377adf1e8dcfff3d242997a57bf11f93fd0d466
5
5
  SHA512:
6
- metadata.gz: 12e94fbaa8060d5fb3cae3464a8837318ba8e2e8f9b85e0bf9e1baae77dd287c773df29dbef8afebff42cd7cebf37fb8750e8ea9ce6395f1c5117785f7317072
7
- data.tar.gz: bfea558e138bc6ce0b0d61cc8636c70f140999902267bed6d9209b48fef7c736b9a482422057ffa3fc5b4ed247c43afd271eb1542ec2a17b88fa84a961745c43
6
+ metadata.gz: a582ba2c81b9cec2c80bff012b9510f1257801dd15665256cbe7058486b2930e570edd34c58e2a03a0ac6106aa6d2b028510682bfb7b9740b8b8bf57c44a9914
7
+ data.tar.gz: 5486cedd9301515c95bae50d5e96c4d4a86a31cf83a8b532bbc131a50c5b28de9169c7d748c5e40cb2df22d8be2d965ebcb618848dc5cf55fde7f9af7139c835
@@ -4,6 +4,7 @@ module Trendable
4
4
 
5
5
  included do
6
6
  scope :order_by_trending, -> { order( trending_power: :desc ) }
7
+ scope :items_to_fade_trending_power, -> { where( "trending_power > 0" ) }
7
8
 
8
9
  def self.has_trendable_concern?
9
10
  true
@@ -11,12 +12,20 @@ module Trendable
11
12
 
12
13
  end
13
14
 
14
- def boost_trending_power!( add_value = 1000 )
15
- self.update_attributes( trending_power: trending_power + add_value )
15
+ def boost_trending_power!( add_value = 1000, dont_touch: false )
16
+ if dont_touch
17
+ self.update_columns( trending_power: trending_power + add_value )
18
+ else
19
+ self.update( trending_power: trending_power + add_value )
20
+ end
16
21
  end
17
22
 
18
- def fade_out_trending_power!( multiplier = 0.9 )
19
- self.update_attributes( trending_power: trending_power * multiplier )
23
+ def fade_out_trending_power!( multiplier = 0.9, dont_touch: false )
24
+ if dont_touch
25
+ self.update_columns( trending_power: trending_power * multiplier )
26
+ else
27
+ self.update( trending_power: trending_power * multiplier )
28
+ end
20
29
  end
21
30
  end
22
31
  end
@@ -1,5 +1,5 @@
1
1
  module Trendable
2
2
  module Rails
3
- VERSION = "1.2.0"
3
+ VERSION = "1.4.1"
4
4
  end
5
5
  end
@@ -1,13 +1,15 @@
1
1
  class FadeOutTrendPowerWorker
2
2
  include Sidekiq::Worker
3
3
 
4
- def perform( multiplier = 0.9 )
4
+ def perform( multiplier = 0.9, batch_size = 1000 )
5
5
  Rails.application.eager_load! if Rails.env.development?
6
6
 
7
7
  ActiveRecord::Base.descendants.each do |klass|
8
8
  if klass.respond_to?( "has_trendable_concern?".to_sym )
9
9
 
10
- klass.update_all( "trending_power = trending_power * #{multiplier}")
10
+ klass.items_to_fade_trending_power.select( :id ).find_in_batches( batch_size: batch_size ) do |batch|
11
+ klass.where( id: batch.collect{ |i| i.id } ).update_all( "trending_power = trending_power * #{multiplier}")
12
+ end
11
13
  else
12
14
  puts "#{klass.to_s} does not have trendable concern"
13
15
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trendable
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff McFadden
@@ -76,8 +76,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
76
76
  - !ruby/object:Gem::Version
77
77
  version: '0'
78
78
  requirements: []
79
- rubyforge_project:
80
- rubygems_version: 2.5.1
79
+ rubygems_version: 3.0.3
81
80
  signing_key:
82
81
  specification_version: 4
83
82
  summary: Organize your models by a trending popularity value