optic-rails 1.3.1 → 1.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/optic/rails.rb +24 -16
- data/lib/optic/rails/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f9410ea4eb57b65685d90e10085ae84f5e40607ed9f1a1016c147c1c3c231efe
|
4
|
+
data.tar.gz: adc15f1add9ac36ccdf2ca8be14a369ab2ba6475072e2298c963d52ddd597d97
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 732f7902ece59b40ec446b17615836b490ba2e94bea9f72ff0b75439274e878f32d85fd057d6854077314256141aa6b8e57dd485cc5c61f72732704097a3b31a
|
7
|
+
data.tar.gz: a53b1d9fb359101ae9a51eb90a0e32c292440a19b951aae377c17a328b591e03f84df378fc15589fdb98c6f6acbd705dd5654d47176d40736059552093c2f063
|
data/lib/optic/rails.rb
CHANGED
@@ -52,30 +52,30 @@ module Optic
|
|
52
52
|
joins = join_path.reverse.map(&:to_sym).inject { |acc, elt| { elt => acc } }
|
53
53
|
|
54
54
|
columns = [
|
55
|
-
%Q|#{qualified_primary_key(pivot)} AS
|
56
|
-
%Q|#{
|
55
|
+
%Q|#{qualified_primary_key(connection, pivot)} AS primary_key|,
|
56
|
+
%Q|#{qualified_entity_column(connection, pivot, instruction["pivot_attribute_name"])} AS pivot_attribute_name|,
|
57
57
|
]
|
58
58
|
|
59
59
|
join_select = entity
|
60
60
|
.joins(joins)
|
61
|
-
.group(qualified_primary_key(pivot))
|
62
|
-
.select(*columns, 'COUNT(*) AS
|
61
|
+
.group(qualified_primary_key(connection, pivot))
|
62
|
+
.select(*columns, 'COUNT(*) AS count')
|
63
63
|
.to_sql
|
64
64
|
|
65
65
|
instance_select = pivot
|
66
|
-
.select(*columns, '0 AS
|
66
|
+
.select(*columns, '0 AS count')
|
67
67
|
.to_sql
|
68
68
|
|
69
69
|
union_sql = <<~"SQL"
|
70
|
-
SELECT
|
71
|
-
FROM (#{join_select} UNION ALL #{instance_select}) AS
|
72
|
-
GROUP BY
|
70
|
+
SELECT pivot_values.primary_key, pivot_values.pivot_attribute_name, MAX(pivot_values.count) AS count
|
71
|
+
FROM (#{join_select} UNION ALL #{instance_select}) AS pivot_values
|
72
|
+
GROUP BY pivot_values.primary_key, pivot_values.pivot_attribute_name
|
73
73
|
SQL
|
74
74
|
else
|
75
|
-
entity.select(
|
75
|
+
entity.select('COUNT(*) as count').to_sql
|
76
76
|
end
|
77
77
|
|
78
|
-
{ metric_configuration_id: instruction["metric_configuration_id"], result: connection.
|
78
|
+
{ metric_configuration_id: instruction["metric_configuration_id"], result: connection.exec_query(query).to_a }
|
79
79
|
end
|
80
80
|
end
|
81
81
|
end
|
@@ -89,8 +89,12 @@ module Optic
|
|
89
89
|
def with_connection
|
90
90
|
ActiveRecord::Base.connection_pool.with_connection do |connection|
|
91
91
|
connection.transaction do
|
92
|
-
connection.
|
93
|
-
|
92
|
+
if connection.adapter_name == "PostgreSQL"
|
93
|
+
connection.execute "SET TRANSACTION READ ONLY"
|
94
|
+
connection.execute "SET LOCAL statement_timeout = 100"
|
95
|
+
# TODO support equivalent options for other adapters (such as mysql)
|
96
|
+
end
|
97
|
+
|
94
98
|
yield connection
|
95
99
|
end
|
96
100
|
end
|
@@ -100,12 +104,16 @@ module Optic
|
|
100
104
|
entity_name.constantize.unscoped
|
101
105
|
end
|
102
106
|
|
103
|
-
def
|
104
|
-
|
107
|
+
def qualified_primary_key(connection, entity)
|
108
|
+
qualified_entity_column(connection, entity, entity.primary_key)
|
109
|
+
end
|
110
|
+
|
111
|
+
def qualified_entity_column(connection, entity, attribute)
|
112
|
+
qualified_table_column(connection, entity.table_name, attribute)
|
105
113
|
end
|
106
114
|
|
107
|
-
def
|
108
|
-
|
115
|
+
def qualified_table_column(connection, table_name, column_name)
|
116
|
+
connection.quote_table_name(table_name) + "." + connection.quote_column_name(column_name)
|
109
117
|
end
|
110
118
|
|
111
119
|
def active_record_klasses
|
data/lib/optic/rails/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: optic-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Anton Vaynshtok
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-07-
|
11
|
+
date: 2018-07-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: action_cable_client
|