punching_bag 0.3.2 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,3 @@
1
1
  module PunchingBag
2
- VERSION = '0.3.2'
2
+ VERSION = '0.3.3'
3
3
  end
@@ -1,29 +1,31 @@
1
1
  namespace :punching_bag do
2
-
3
2
  desc 'Combine old hit records together to improve performance'
4
3
  task :combine, [:by_day_after, :by_month_after, :by_year_after] => [:environment] do |t, args|
5
- args.with_defaults :by_day_after => 7, :by_month_after => 1, :by_year_after => 1
6
-
7
- punchables = Punch.all.map(&:punchable).uniq
8
- punchables.each do |punchable|
9
-
10
- # by_year
11
- punchable.punches.before(args[:by_year_after].years.ago).each do |punch|
12
- punch.combine_by_year
13
- end
14
-
15
- # by_month
16
- punchable.punches.before(args[:by_month_after].months.ago).each do |punch|
17
- punch.combine_by_month
18
- end
19
-
20
- # by_day
21
- punchable.punches.before(args[:by_day_after].days.ago).each do |punch|
22
- punch.combine_by_day
4
+ args.with_defaults :by_day_after => 7, :by_month_after => 1, :by_year_after => 1
5
+
6
+ punchable_types = Punch.uniq.pluck(:punchable_type)
7
+
8
+ punchable_types.each do |punchable_type|
9
+ punchable_ids = Punch.uniq.where(punchable_type: punchable_type).pluck(:punchable_id)
10
+
11
+ punchable_ids.each do |punchable_id|
12
+ punchable = punchable_type.constantize.find(punchable_id)
13
+
14
+ # by_year
15
+ punchable.punches.before(args[:by_year_after].years.ago).each do |punch|
16
+ punch.combine_by_year
17
+ end
18
+
19
+ # by_month
20
+ punchable.punches.before(args[:by_month_after].months.ago).each do |punch|
21
+ punch.combine_by_month
22
+ end
23
+
24
+ # by_day
25
+ punchable.punches.before(args[:by_day_after].days.ago).each do |punch|
26
+ punch.combine_by_day
27
+ end
23
28
  end
24
-
25
29
  end
26
-
27
30
  end
28
-
29
- end
31
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: punching_bag
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 2
10
- version: 0.3.2
9
+ - 3
10
+ version: 0.3.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Adam Crownoble
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2013-06-05 00:00:00 Z
18
+ date: 2013-06-06 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: voight_kampff