rails_surrogate_key_logging 1.0.0 → 1.2.0
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/models/surrogate_key_logging/surrogate.rb +7 -5
- data/lib/surrogate_key_logging/engine.rb +4 -0
- data/lib/surrogate_key_logging/key_manager.rb +2 -6
- data/lib/surrogate_key_logging/key_store/active_record.rb +9 -17
- data/lib/surrogate_key_logging/key_store/base.rb +1 -13
- data/lib/surrogate_key_logging/middleware.rb +16 -0
- data/lib/surrogate_key_logging/sidekiq.rb +40 -0
- data/lib/surrogate_key_logging/version.rb +1 -1
- data/lib/surrogate_key_logging.rb +3 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8ffb01158739d8e9483393f18c917c77a17ef7632153c831f15856ec737faf2f
|
4
|
+
data.tar.gz: 54c085f0021eadfa90cb57c86c72327aa2dece0ff5b21a6b1abbf2dfdcbf6bf2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 332f4dbc5a940d9f761236ca335acf8314ed297e32be30146ef2f8b1d12e6c4ae2f3b29ec3c06ec21a16f5d9586134a756c17655446dd79b2d23be5aba464c9c
|
7
|
+
data.tar.gz: d59829e5426f10e971d32d3390017b6c370f4d0552cd84ff5eab16d5224959e75c1769e976f265c03150f86d2ac46913ac86474cf73f1e499813597976325b7d
|
@@ -15,14 +15,16 @@ module SurrogateKeyLogging
|
|
15
15
|
where(hashed_value: hash_value(value)).select(:key).first&.key
|
16
16
|
end
|
17
17
|
|
18
|
-
def add(surrogate, value)
|
19
|
-
s = new(key: surrogate, value: value, hashed_value: hash_value(value))
|
20
|
-
s.save
|
21
|
-
end
|
22
|
-
|
23
18
|
def use(surrogate)
|
24
19
|
where(key: surrogate).touch_all
|
25
20
|
end
|
21
|
+
|
22
|
+
def find_or_create_surrogate_for_value(value, key_for)
|
23
|
+
hashed_value = hash_value(value)
|
24
|
+
upsert_all([{key: key_for.call(value), value: value, hashed_value: hashed_value}], update_only: 'updated_at')
|
25
|
+
where(hashed_value: hashed_value).select(:key).first.key
|
26
|
+
end
|
27
|
+
|
26
28
|
end
|
27
29
|
end
|
28
30
|
end
|
@@ -34,6 +34,10 @@ module SurrogateKeyLogging
|
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
+
initializer 'surrogate_key_logging.middleware' do |app|
|
38
|
+
app.middleware.insert_before(0, Middleware)
|
39
|
+
end
|
40
|
+
|
37
41
|
initializer 'surrogate_key_logging.filter_parameters' do
|
38
42
|
if SurrogateKeyLogging.config.enabled
|
39
43
|
end
|
@@ -28,13 +28,9 @@ module SurrogateKeyLogging
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def get_non_cached(value)
|
31
|
-
|
32
|
-
return stored if stored.present?
|
33
|
-
surrogate = key_for.call(value)
|
34
|
-
key_store.save(surrogate, value)
|
35
|
-
surrogate
|
31
|
+
key_store.get(value)
|
36
32
|
end
|
37
|
-
|
33
|
+
|
38
34
|
def call(_key, value, _parents = [], _original_params = nil)
|
39
35
|
return "" if value.blank?
|
40
36
|
surrogate = get(value)
|
@@ -5,7 +5,7 @@ module SurrogateKeyLogging
|
|
5
5
|
|
6
6
|
class ActiveRecord < Base
|
7
7
|
|
8
|
-
attr_reader :model
|
8
|
+
attr_reader :model, :key_for
|
9
9
|
|
10
10
|
def initialize
|
11
11
|
if SurrogateKeyLogging.config.key?(:model) && SurrogateKeyLogging.config.model.present?
|
@@ -14,24 +14,16 @@ module SurrogateKeyLogging
|
|
14
14
|
else
|
15
15
|
@model = SurrogateKeyLogging::Surrogate
|
16
16
|
end
|
17
|
+
@key_for = SurrogateKeyLogging.config.key_for
|
17
18
|
end
|
18
19
|
|
19
|
-
def
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
model.value_for_surrogate(surrogate)
|
27
|
-
end
|
28
|
-
|
29
|
-
def save(surrogate, value)
|
30
|
-
model.add(surrogate, value)
|
31
|
-
end
|
32
|
-
|
33
|
-
def use(surrogate)
|
34
|
-
model.use(surrogate)
|
20
|
+
def get(value)
|
21
|
+
_get = -> { model.find_or_create_surrogate_for_value(value, key_for) }
|
22
|
+
if SurrogateKeyLogging.config.debug
|
23
|
+
_get.call
|
24
|
+
else
|
25
|
+
::ActiveRecord::Base.logger.silence { _get.call }
|
26
|
+
end
|
35
27
|
end
|
36
28
|
|
37
29
|
end
|
@@ -4,19 +4,7 @@ module SurrogateKeyLogging
|
|
4
4
|
module KeyStore
|
5
5
|
class Base
|
6
6
|
|
7
|
-
def
|
8
|
-
raise NotImplementedError
|
9
|
-
end
|
10
|
-
|
11
|
-
def value_for_surrogate(surrogate)
|
12
|
-
raise NotImplementedError
|
13
|
-
end
|
14
|
-
|
15
|
-
def save(surrogate, value)
|
16
|
-
raise NotImplementedError
|
17
|
-
end
|
18
|
-
|
19
|
-
def use(surrogate)
|
7
|
+
def get(value, generator)
|
20
8
|
raise NotImplementedError
|
21
9
|
end
|
22
10
|
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
if defined?(::Sidekiq)
|
4
|
+
module Sidekiq
|
5
|
+
if defined?(Worker)
|
6
|
+
module Worker::ClassMethods
|
7
|
+
def surrogate_params(*attrs)
|
8
|
+
@surrogate_params ||= []
|
9
|
+
attrs.each do |attr|
|
10
|
+
@surrogate_params << attr.to_sym
|
11
|
+
end
|
12
|
+
@surrogate_params
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
if defined?(JobLogger)
|
18
|
+
class JobLogger
|
19
|
+
alias_method :job_hash_context__before_surrogate_key_logging, :job_hash_context
|
20
|
+
def job_hash_context(job_hash)
|
21
|
+
hash = job_hash_context__before_surrogate_key_logging(job_hash).stringify_keys
|
22
|
+
hash['args'] = {}
|
23
|
+
if job_hash.key?('args')
|
24
|
+
begin
|
25
|
+
klass = hash['class'].constantize
|
26
|
+
perform = klass.instance_method(:perform)
|
27
|
+
params = perform.parameters
|
28
|
+
params.each_with_index do |param, i|
|
29
|
+
hash['args'][param.last] = job_hash['args'][i]
|
30
|
+
end
|
31
|
+
hash['args'] = SurrogateKeyLogging.filter_for_attributes(klass.surrogate_params).filter(hash['args'])
|
32
|
+
end
|
33
|
+
end
|
34
|
+
hash
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
@@ -12,12 +12,14 @@ module SurrogateKeyLogging
|
|
12
12
|
autoload :ActiveRecord
|
13
13
|
autoload :Config, 'surrogate_key_logging/configuration'
|
14
14
|
autoload :Configuration
|
15
|
+
autoload :Engine
|
15
16
|
autoload :KeyManager
|
16
17
|
autoload :KeyStore
|
17
18
|
autoload :Middleware
|
18
|
-
autoload :Engine
|
19
19
|
autoload :Version
|
20
20
|
|
21
|
+
require 'surrogate_key_logging/sidekiq' if defined?(::Sidekiq)
|
22
|
+
|
21
23
|
@config = Config.new
|
22
24
|
|
23
25
|
class << self
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_surrogate_key_logging
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Taylor Yelverton
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-05-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionpack
|
@@ -120,6 +120,8 @@ files:
|
|
120
120
|
- lib/surrogate_key_logging/key_store.rb
|
121
121
|
- lib/surrogate_key_logging/key_store/active_record.rb
|
122
122
|
- lib/surrogate_key_logging/key_store/base.rb
|
123
|
+
- lib/surrogate_key_logging/middleware.rb
|
124
|
+
- lib/surrogate_key_logging/sidekiq.rb
|
123
125
|
- lib/surrogate_key_logging/version.rb
|
124
126
|
- lib/tasks/key_store/active_record.rake
|
125
127
|
- lib/tasks/surrogate_key_logging.rake
|