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 +5 -5
- data/lib/concerns/trendable.rb +13 -4
- data/lib/trendable/version.rb +1 -1
- data/lib/workers/fade_out_trend_power_worker.rb +4 -2
- metadata +2 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 03460e66c631e8ed7144e8d6cf2ad7fe33535cfbd51e25709ee9ca45b2bec78a
|
4
|
+
data.tar.gz: 285845241d9f4699d93e5bb92377adf1e8dcfff3d242997a57bf11f93fd0d466
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a582ba2c81b9cec2c80bff012b9510f1257801dd15665256cbe7058486b2930e570edd34c58e2a03a0ac6106aa6d2b028510682bfb7b9740b8b8bf57c44a9914
|
7
|
+
data.tar.gz: 5486cedd9301515c95bae50d5e96c4d4a86a31cf83a8b532bbc131a50c5b28de9169c7d748c5e40cb2df22d8be2d965ebcb618848dc5cf55fde7f9af7139c835
|
data/lib/concerns/trendable.rb
CHANGED
@@ -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
|
-
|
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
|
-
|
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
|
data/lib/trendable/version.rb
CHANGED
@@ -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.
|
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.
|
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
|
-
|
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
|