rails_surrogate_key_logging 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- 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/version.rb +1 -1
- metadata +3 -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
|
|
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-05-
|
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,7 @@ 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
|
123
124
|
- lib/surrogate_key_logging/sidekiq.rb
|
124
125
|
- lib/surrogate_key_logging/version.rb
|
125
126
|
- lib/tasks/key_store/active_record.rake
|