Class: WorkerPlugins::ApplicationService
- Inherits:
-
ServicePattern::Service
- Object
- ServicePattern::Service
- WorkerPlugins::ApplicationService
show all
- Defined in:
- app/services/worker_plugins/application_service.rb
Instance Method Summary
collapse
Instance Method Details
#db_now_value ⇒ Object
2
3
4
5
6
7
8
9
10
11
12
|
# File 'app/services/worker_plugins/application_service.rb', line 2
def db_now_value
@db_now_value ||= begin
time_string = Time.zone.now.strftime("%Y-%m-%d %H:%M:%S")
if postgres?
"CAST(#{quote(time_string)} AS TIMESTAMP)"
else
quote(time_string)
end
end
end
|
#mysql? ⇒ Boolean
34
35
36
37
38
|
# File 'app/services/worker_plugins/application_service.rb', line 34
def mysql?
adapter_name = ActiveRecord::Base.connection.instance_values["config"][:adapter].downcase
adapter_name.include?("mysql") || adapter_name.include?("trilogy")
end
|
#postgres? ⇒ Boolean
26
27
28
|
# File 'app/services/worker_plugins/application_service.rb', line 26
def postgres?
ActiveRecord::Base.connection.instance_values["config"][:adapter].downcase.include?("postgres")
end
|
#quote(value) ⇒ Object
14
15
16
|
# File 'app/services/worker_plugins/application_service.rb', line 14
def quote(value)
WorkerPlugins::Workplace.connection.quote(value)
end
|
#quote_column(value) ⇒ Object
18
19
20
|
# File 'app/services/worker_plugins/application_service.rb', line 18
def quote_column(value)
WorkerPlugins::Workplace.connection.quote_column_name(value)
end
|
#quote_table(value) ⇒ Object
22
23
24
|
# File 'app/services/worker_plugins/application_service.rb', line 22
def quote_table(value)
WorkerPlugins::Workplace.connection.quote_table_name(value)
end
|
#relation_unscoped?(relation) ⇒ Boolean
True when a relation applies no row-narrowing scope — so filtering workplace links with ‘resource_id IN (SELECT … FROM <target_table>)` adds no semantic value and just forces the database to materialize every row of the target model. Call sites (RemoveQuery, QueryLinksStatus) use this to drop the subquery and count/delete by `resource_type` alone on large target models (e.g. 340k+ users).
46
47
48
49
50
51
52
53
54
55
56
|
# File 'app/services/worker_plugins/application_service.rb', line 46
def relation_unscoped?(relation)
relation.where_clause.empty? &&
relation.joins_values.empty? &&
relation.left_outer_joins_values.empty? &&
relation.group_values.empty? &&
relation.having_clause.empty? &&
relation.limit_value.nil? &&
relation.offset_value.nil? &&
relation.from_clause.value.nil? &&
relation.with_values.empty?
end
|
#sqlite? ⇒ Boolean
30
31
32
|
# File 'app/services/worker_plugins/application_service.rb', line 30
def sqlite?
ActiveRecord::Base.connection.instance_values["config"][:adapter].downcase.include?("sqlite")
end
|