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 +4 -4
- data/app/services/worker_plugins/add_query.rb +35 -11
- data/lib/worker_plugins/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: 13eab7a67becfdbd1809b1930d1314a86c6c0cb217d39ae19181e1dec7453976
|
|
4
|
+
data.tar.gz: 65b838cc21313b78f92d43b85a95adba991f50360d05be8ec11a2050b4b75133
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
|
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
|
-
|
|
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
|
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.
|
|
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-
|
|
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.
|