optic-rails 1.2.0 → 1.3.0
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 +11 -12
- data/lib/optic/rails/railtie.rb +0 -2
- 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: a31dc5831c0497221df21911c8b1d3e19823e8757571fb543530d78649c1d836
|
4
|
+
data.tar.gz: 0d8d44c7978a12e9f5b0fc5da2bb6b1e7c1dfb8c9868bb66abb5814b78218c02
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b3a385d803cfd40bff67dddf437c69857fc08a0bee5ac9d71e096239ddd3c5f7ffc4a4d0d17482404bce939f930af1ff20af0f8bc44deb194bee74b527988394
|
7
|
+
data.tar.gz: b5b7c3c6a8c1c8fba53981cbd30144a9991350501784605e52e530e8b7e19419370371f854c38ea214c350b079e22745b3aabdf8db20c74741520bbf55193a5e
|
data/lib/optic/rails.rb
CHANGED
@@ -50,20 +50,26 @@ module Optic
|
|
50
50
|
pivot = pivot_name.constantize
|
51
51
|
join_path = instruction["join_path"]
|
52
52
|
joins = join_path.reverse.map(&:to_sym).inject { |acc, elt| { elt => acc } }
|
53
|
+
|
54
|
+
columns = [
|
55
|
+
%Q|#{qualified_primary_key(pivot)} AS "primary_key"|,
|
56
|
+
%Q|#{qualified_column(pivot, instruction["pivot_attribute_name"])} AS "pivot_attribute_name"|,
|
57
|
+
]
|
58
|
+
|
53
59
|
join_select = entity
|
54
60
|
.joins(joins)
|
55
61
|
.group(qualified_primary_key(pivot))
|
56
|
-
.select(
|
62
|
+
.select(*columns, 'COUNT(*) AS "count"')
|
57
63
|
.to_sql
|
58
64
|
|
59
65
|
instance_select = pivot
|
60
|
-
.select(
|
66
|
+
.select(*columns, '0 AS "count"')
|
61
67
|
.to_sql
|
62
68
|
|
63
69
|
union_sql = <<~"SQL"
|
64
|
-
SELECT "pivot_values"."
|
65
|
-
FROM (#{join_select} UNION ALL #{instance_select}) AS pivot_values
|
66
|
-
GROUP BY "pivot_values"."
|
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"
|
67
73
|
SQL
|
68
74
|
else
|
69
75
|
entity.select("COUNT(*)").to_sql
|
@@ -74,13 +80,6 @@ module Optic
|
|
74
80
|
end
|
75
81
|
end
|
76
82
|
|
77
|
-
def instances(pivot_name)
|
78
|
-
with_connection do |connection|
|
79
|
-
pivot = pivot_name.constantize
|
80
|
-
{ instances: connection.execute(pivot.unscoped.select("*").to_sql).to_a }
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
83
|
private
|
85
84
|
|
86
85
|
# Try to be defensive with our DB connection:
|
data/lib/optic/rails/railtie.rb
CHANGED
@@ -69,8 +69,6 @@ module Optic
|
|
69
69
|
client.perform "schema", message: Optic::Rails.entities
|
70
70
|
when "request_metrics"
|
71
71
|
client.perform "metrics", message: Optic::Rails.metrics(message["instructions"])
|
72
|
-
when "request_instances"
|
73
|
-
client.perform "instances", message: Optic::Rails.instances(message["pivot"])
|
74
72
|
else
|
75
73
|
logger.warn "Optic agent got unknown command: #{command}"
|
76
74
|
end
|
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.
|
4
|
+
version: 1.3.0
|
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-
|
11
|
+
date: 2018-07-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: action_cable_client
|