worker_plugins 0.0.13 → 0.0.14

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2f77ed60aa6667fcc2fc18e2205e6e2a2c9dffd5fba9499750fc9dbcdea61bf5
4
- data.tar.gz: 4292d9a83b73e309e731e00d393d7029750d1a7b6ddbe3685f7379af1efc61c6
3
+ metadata.gz: 13eab7a67becfdbd1809b1930d1314a86c6c0cb217d39ae19181e1dec7453976
4
+ data.tar.gz: 65b838cc21313b78f92d43b85a95adba991f50360d05be8ec11a2050b4b75133
5
5
  SHA512:
6
- metadata.gz: 6aa418455aa98b9068bfa46c71eaf12e9a9943c5f1591e015cd713e7bf0d034beff33d98c15506dadd348811834451958f8d11018407910e0da1c29580059430
7
- data.tar.gz: 7e1a09482cca627de3794587a480be4f695e9422bec933abc514ddabd3546c2b05485c0da1c141ed4ae0356ab41943607875bed7e376787050ada52e25551b19
6
+ metadata.gz: 46ebc5d54657090702d0280e72c5f0d863effcbe7ea478892f492b81bfba829a478220fddbde9f2c9df9e7dc7efc07fa3ec5518aa6b455de81be41c7297e72d9
7
+ data.tar.gz: 4b76bdfa275a1641d782ef84bc96e5e6658d866fb4aef3831f82986dabea510a4e61becb19179bf6a80535181b2492bd939346da8e53c7c110fd36940f181cf7
@@ -24,7 +24,7 @@ class WorkerPlugins::AddQuery < WorkerPlugins::ApplicationService
24
24
  def ids_added_already_query
25
25
  workplace
26
26
  .workplace_links
27
- .where(resource_type: model_class.name, resource_id: query_with_selected_ids)
27
+ .where(resource_type: model_class.name)
28
28
  end
29
29
 
30
30
  def ids_added_already
@@ -43,19 +43,43 @@ class WorkerPlugins::AddQuery < WorkerPlugins::ApplicationService
43
43
  @primary_key ||= resources_to_add.klass.primary_key
44
44
  end
45
45
 
46
- def query_with_selected_ids
47
- WorkerPlugins::SelectColumnWithTypeCast.execute!(
48
- column_name_to_select: :id,
49
- column_to_compare_with: WorkerPlugins::WorkplaceLink.column_for_attribute(:resource_id),
50
- query:
51
- )
52
- end
53
-
54
46
  def resources_to_add
47
+ # Correlate per row with NOT EXISTS instead of NOT IN + a materialized
48
+ # subquery. The old form expanded into a nested `resource_id IN (SELECT
49
+ # CAST(users.id AS CHAR) FROM users)` that did a full scan of the target
50
+ # table when the outer query was unfiltered — 60s+ on 340k+ users. This
51
+ # uses the `(workplace_id, resource_type, resource_id)` composite index
52
+ # for an index seek per row.
55
53
  @resources_to_add ||= query
56
54
  .distinct
57
- .where
58
- .not(id: ids_added_already)
55
+ .where("NOT EXISTS (#{existing_workplace_link_exists_sql})")
56
+ end
57
+
58
+ def existing_workplace_link_exists_sql
59
+ resource_id_column = "#{quote_table(WorkerPlugins::WorkplaceLink.table_name)}.#{quote_column(:resource_id)}"
60
+
61
+ workplace
62
+ .workplace_links
63
+ .where(resource_type: model_class.name)
64
+ .where("#{resource_id_column} = #{model_primary_key_cast_for_resource_id}")
65
+ .select(1)
66
+ .to_sql
67
+ end
68
+
69
+ def model_primary_key_cast_for_resource_id
70
+ primary_key_column = "#{quote_table(model_class.table_name)}.#{quote_column(model_class.primary_key)}"
71
+
72
+ # MySQL and SQLite do implicit conversion when comparing integer/uuid/string
73
+ # primary keys to the `resource_id` VARCHAR column. Postgres is strict about
74
+ # types and needs an explicit cast.
75
+ return primary_key_column unless postgres?
76
+
77
+ primary_key_type = model_class.column_for_attribute(model_class.primary_key).type
78
+ resource_id_type = WorkerPlugins::WorkplaceLink.column_for_attribute(:resource_id).type
79
+
80
+ return primary_key_column if primary_key_type == resource_id_type
81
+
82
+ "CAST(#{primary_key_column} AS VARCHAR)"
59
83
  end
60
84
 
61
85
  def select_sql
@@ -1,3 +1,3 @@
1
1
  module WorkerPlugins
2
- VERSION = "0.0.13".freeze
2
+ VERSION = "0.0.14".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: worker_plugins
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.13
4
+ version: 0.0.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kasper Stöckel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-04-15 00:00:00.000000000 Z
11
+ date: 2026-04-22 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Rails framework for easily choosing and creating lists of objects and
14
14
  execute plugins against them.