resque-reports 0.3.3 → 0.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +8 -8
- data/lib/resque/reports/common/batched_report.rb +119 -113
- data/lib/resque/reports/common.rb +13 -0
- data/lib/resque/reports/version.rb +1 -1
- data/lib/resque/reports.rb +1 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZTg5NDgzYTkwN2Q1ZDllNzI5Y2JlM2FkMzdkZjk2MTUyYmRkNGI2ZQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NTAyOWU0NDhkOWI3Mzc5OWM5MTk4YWJhMTVmOWUzNjFkYjcyODhjMA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YTQ4ZTc4MDA4NTdhYTk3ZTM1MTNmZjdiMmM4ZjJmZTg5MzI2M2VlZjk5M2Ux
|
10
|
+
MDdiM2EwN2M0NzhmMDU4ZDljM2UxNTBiZDJiNWU3MDI5NWMwM2VjY2MwYjFh
|
11
|
+
MzU3NDRhMDhjZmU5ZTI1YzU4Yzg1NGJlYmUxY2U3ZmQ2NjUwMzQ=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
OTJhNzlmMGMwNTM1ODFjMzBiYjU2ZDlmNjc4M2Y4YzFkNTRjNWIxNzhiZGQ2
|
14
|
+
MGE5NjE0NjY1ZWUxN2IzYzhkMmQxOTUwN2I5N2Y5YmQ4ZDM5ZDAwZDBhNGMy
|
15
|
+
OTk1Mzk3MWExNTQ0NWFmNDRmYTIwMzExMTc1NzdjYmQ5NDk3ZmE=
|
@@ -1,119 +1,125 @@
|
|
1
1
|
# coding: utf-8
|
2
|
-
module Resque
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
2
|
+
module Resque
|
3
|
+
module Reports
|
4
|
+
module Common
|
5
|
+
module BatchedReport
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
BATCH_SIZE = 10_000
|
9
|
+
|
10
|
+
module InstanceMethods
|
11
|
+
# Internal: Выполняет запрос отчета пачками и выполняет block для каждой пачки
|
12
|
+
# Переопредленный метод из Resque::Reports
|
13
|
+
#
|
14
|
+
# Returns Nothing
|
15
|
+
def data_each(force = false)
|
16
|
+
0.step(data_size, batch_size) do |batch_offset|
|
17
|
+
ActiveRecord::Base.connection.execute(batched_query(batch_offset)).each do |element|
|
18
|
+
yield element
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# Internal: Возвращает общее кол-во строк в отчете
|
24
|
+
# Переопредленный метод из Resque::Reports
|
25
|
+
#
|
26
|
+
# Returns Fixnum
|
27
|
+
def data_size
|
28
|
+
@data_size ||= ActiveRecord::Base.connection.execute(count_query)[0]['count'].to_i
|
29
|
+
end
|
30
|
+
|
31
|
+
protected
|
32
|
+
|
33
|
+
# Internal: Возвращает отфильтрованный запрос отчета
|
34
|
+
#
|
35
|
+
# Returns Arel::SelectManager
|
36
|
+
def query
|
37
|
+
filter base_query
|
38
|
+
end
|
39
|
+
|
40
|
+
# Internal: Полезный метод для хранения Arel::Table объектов для запроса отчета
|
41
|
+
#
|
42
|
+
# Returns Hash, {:table_name => #<Arel::Table @name="table_name">, ...}
|
43
|
+
def tables
|
44
|
+
return @tables if defined? @tables
|
45
|
+
|
46
|
+
tables = models.map(&:arel_table)
|
47
|
+
|
48
|
+
@tables = tables.inject({}) { |a, e| a.store(e.name, e) && a }.with_indifferent_access
|
49
|
+
end
|
50
|
+
|
51
|
+
# Internal: Полезный метод для join'а необходимых таблиц через Arel
|
52
|
+
#
|
53
|
+
# Returns Arel
|
54
|
+
def join_tables(source_table, joins)
|
55
|
+
joins.inject(source_table) do |query, joined|
|
56
|
+
query.join(joined[:table]).on(joined[:on])
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
# Internal: Размер пачки отчета
|
61
|
+
#
|
62
|
+
# Returns Fixnum
|
63
|
+
def batch_size
|
64
|
+
BATCH_SIZE
|
65
|
+
end
|
66
|
+
|
67
|
+
# Internal: Модели используемые в отчете
|
68
|
+
#
|
69
|
+
# Returns Array of Arel::Table
|
70
|
+
def models
|
71
|
+
fail NotImplementedError
|
72
|
+
end
|
73
|
+
|
74
|
+
# Internal: Основной запрос отчета (Arel)
|
75
|
+
#
|
76
|
+
# Returns Arel::SelectManager
|
77
|
+
def base_query
|
78
|
+
fail NotImplementedError
|
79
|
+
end
|
80
|
+
|
81
|
+
# Internal: Поля запрашиваемые отчетом
|
82
|
+
#
|
83
|
+
# Returns String (SQL)
|
84
|
+
def select
|
85
|
+
fail NotImplementedError
|
86
|
+
end
|
87
|
+
|
88
|
+
# Internal: Порядок строк отчета
|
89
|
+
#
|
90
|
+
# Returns String (SQL)
|
91
|
+
def order
|
92
|
+
nil
|
93
|
+
end
|
94
|
+
|
95
|
+
# Internal: Фильтры отчета
|
96
|
+
#
|
97
|
+
# Returns Arel::SelectManager
|
98
|
+
def filter(query)
|
99
|
+
query
|
100
|
+
end
|
101
|
+
|
102
|
+
# Internal: Запрос количества строк в отчете
|
103
|
+
#
|
104
|
+
# Returns String (SQL)
|
105
|
+
def count_query
|
106
|
+
query.project(Arel.sql('COUNT(*) as count')).to_sql
|
107
|
+
end
|
108
|
+
|
109
|
+
# Internal: Запрос пачки строк отчета
|
110
|
+
#
|
111
|
+
# offset - Numeric, число строк на которое сдвигается запрос
|
112
|
+
#
|
113
|
+
# Returns String (SQL)
|
114
|
+
def batched_query(offset)
|
115
|
+
query.project(Arel.sql(select))
|
116
|
+
.take(batch_size)
|
117
|
+
.skip(offset)
|
118
|
+
.order(order)
|
119
|
+
.to_sql
|
120
|
+
end
|
16
121
|
end
|
17
122
|
end
|
18
123
|
end
|
19
|
-
|
20
|
-
# Internal: Возвращает общее кол-во строк в отчете
|
21
|
-
# Переопредленный метод из Resque::Reports
|
22
|
-
#
|
23
|
-
# Returns Fixnum
|
24
|
-
def data_size
|
25
|
-
@data_size ||= ActiveRecord::Base.connection.execute(count_query)[0]['count'].to_i
|
26
|
-
end
|
27
|
-
|
28
|
-
protected
|
29
|
-
|
30
|
-
# Internal: Возвращает отфильтрованный запрос отчета
|
31
|
-
#
|
32
|
-
# Returns Arel::SelectManager
|
33
|
-
def query
|
34
|
-
filter base_query
|
35
|
-
end
|
36
|
-
|
37
|
-
# Internal: Полезный метод для хранения Arel::Table объектов для запроса отчета
|
38
|
-
#
|
39
|
-
# Returns Hash, {:table_name => #<Arel::Table @name="table_name">, ...}
|
40
|
-
def tables
|
41
|
-
return @tables if defined? @tables
|
42
|
-
|
43
|
-
tables = models.map(&:arel_table)
|
44
|
-
|
45
|
-
@tables = tables.inject({}) { |a, e| a.store(e.name, e) && a }.with_indifferent_access
|
46
|
-
end
|
47
|
-
|
48
|
-
# Internal: Полезный метод для join'а необходимых таблиц через Arel
|
49
|
-
#
|
50
|
-
# Returns Arel
|
51
|
-
def join_tables(source_table, joins)
|
52
|
-
joins.inject(source_table) do |query, joined|
|
53
|
-
query.join(joined[:table]).on(joined[:on])
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
# Internal: Размер пачки отчета
|
58
|
-
#
|
59
|
-
# Returns Fixnum
|
60
|
-
def batch_size
|
61
|
-
BATCH_SIZE
|
62
|
-
end
|
63
|
-
|
64
|
-
# Internal: Модели используемые в отчете
|
65
|
-
#
|
66
|
-
# Returns Array of Arel::Table
|
67
|
-
def models
|
68
|
-
fail NotImplementedError
|
69
|
-
end
|
70
|
-
|
71
|
-
# Internal: Основной запрос отчета (Arel)
|
72
|
-
#
|
73
|
-
# Returns Arel::SelectManager
|
74
|
-
def base_query
|
75
|
-
fail NotImplementedError
|
76
|
-
end
|
77
|
-
|
78
|
-
# Internal: Поля запрашиваемые отчетом
|
79
|
-
#
|
80
|
-
# Returns String (SQL)
|
81
|
-
def select
|
82
|
-
fail NotImplementedError
|
83
|
-
end
|
84
|
-
|
85
|
-
# Internal: Порядок строк отчета
|
86
|
-
#
|
87
|
-
# Returns String (SQL)
|
88
|
-
def order
|
89
|
-
nil
|
90
|
-
end
|
91
|
-
|
92
|
-
# Internal: Фильтры отчета
|
93
|
-
#
|
94
|
-
# Returns Arel::SelectManager
|
95
|
-
def filter(query)
|
96
|
-
query
|
97
|
-
end
|
98
|
-
|
99
|
-
# Internal: Запрос количества строк в отчете
|
100
|
-
#
|
101
|
-
# Returns String (SQL)
|
102
|
-
def count_query
|
103
|
-
query.project(Arel.sql('COUNT(*) as count')).to_sql
|
104
|
-
end
|
105
|
-
|
106
|
-
# Internal: Запрос пачки строк отчета
|
107
|
-
#
|
108
|
-
# offset - Numeric, число строк на которое сдвигается запрос
|
109
|
-
#
|
110
|
-
# Returns String (SQL)
|
111
|
-
def batched_query(offset)
|
112
|
-
query.project(Arel.sql(select))
|
113
|
-
.take(batch_size)
|
114
|
-
.skip(offset)
|
115
|
-
.order(order)
|
116
|
-
.to_sql
|
117
|
-
end
|
118
124
|
end
|
119
125
|
end
|
data/lib/resque/reports.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: resque-reports
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sergey D.
|
@@ -128,6 +128,7 @@ files:
|
|
128
128
|
- lib/resque/reports.rb
|
129
129
|
- lib/resque/reports/base_report.rb
|
130
130
|
- lib/resque/reports/cache_file.rb
|
131
|
+
- lib/resque/reports/common.rb
|
131
132
|
- lib/resque/reports/common/batched_report.rb
|
132
133
|
- lib/resque/reports/csv_report.rb
|
133
134
|
- lib/resque/reports/extensions.rb
|