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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0aa2f63c9f4f258d67ea8394f6cd7bade5bcdfa4bb8688b52797060224034e2d
4
- data.tar.gz: 0211d9654d0bcde150cdaef99c44a69016a96ecf2f592c11b5c560b13a1b97a1
3
+ metadata.gz: a31dc5831c0497221df21911c8b1d3e19823e8757571fb543530d78649c1d836
4
+ data.tar.gz: 0d8d44c7978a12e9f5b0fc5da2bb6b1e7c1dfb8c9868bb66abb5814b78218c02
5
5
  SHA512:
6
- metadata.gz: 1c211a4e662524ac0db1b2f858603de478d57b074a0959904f8a5142b5e56d12cc89d21aa653bf7509247132a2da5c803f34b6d51eacd122443203dc0739ae6d
7
- data.tar.gz: 245695dd27b14e22afbdbd4aa5df1f08e0ee8f0635ccbe85aea7eacf98043958412414c48846001a13d4e22628c6c13b651232a198388eb6a2f84a2813b521c2
6
+ metadata.gz: b3a385d803cfd40bff67dddf437c69857fc08a0bee5ac9d71e096239ddd3c5f7ffc4a4d0d17482404bce939f930af1ff20af0f8bc44deb194bee74b527988394
7
+ data.tar.gz: b5b7c3c6a8c1c8fba53981cbd30144a9991350501784605e52e530e8b7e19419370371f854c38ea214c350b079e22745b3aabdf8db20c74741520bbf55193a5e
@@ -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(qualified_primary_key(pivot), qualified_column(pivot, instruction["pivot_attribute_name"]), "COUNT(*)")
62
+ .select(*columns, 'COUNT(*) AS "count"')
57
63
  .to_sql
58
64
 
59
65
  instance_select = pivot
60
- .select(qualified_primary_key(pivot), qualified_column(pivot, instruction["pivot_attribute_name"]), "0 as count")
66
+ .select(*columns, '0 AS "count"')
61
67
  .to_sql
62
68
 
63
69
  union_sql = <<~"SQL"
64
- SELECT "pivot_values"."id", "pivot_values"."name", MAX("pivot_values"."count") AS count
65
- FROM (#{join_select} UNION ALL #{instance_select}) AS pivot_values
66
- GROUP BY "pivot_values"."id", "pivot_values"."name"
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:
@@ -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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Optic
4
4
  module Rails
5
- VERSION = "1.2.0"
5
+ VERSION = "1.3.0"
6
6
  end
7
7
  end
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.2.0
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-06-27 00:00:00.000000000 Z
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