db_memoize 0.3.9 → 0.3.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/lib/db_memoize/value.rb +28 -35
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 520170b67792fdb3910895e3c510d6085cbd8666a306d357fdbd61236981c958
4
- data.tar.gz: 921d0f58c8757bfc145132e95495f444d8d10cabc3fef247ae945faecc84e883
3
+ metadata.gz: eccd7dee2a2a8e43545c7adfc0fcf471a5cd59d2a06b02dfdd8e6adea8f6352e
4
+ data.tar.gz: 4683ab98fab4e440b3e61124d9c1ae30fcb87b7d939814f874702cc23f020602
5
5
  SHA512:
6
- metadata.gz: 356ede40ddf8a75be14043d01fa83fad462c6df3adc0c28db8a18a866276fdbd7b51c9ad8aef7e6236215f6f623fdbdde5575f987bb46807ddbe425e81e1a12e
7
- data.tar.gz: 4c386fbe295073209a55ebac0ff4e03ac97037810fa7b42d7690ce7c4d05f92727887f00e7a9f2045e865b157ad7026607a6899d305d57381437f583c9304e3e
6
+ metadata.gz: 374ff41e01ec60b1e3e51f2e99969aa13199b512e364bf376462b79fdbf79e0fc07b25988da1f9619f0f6b1e588cea3934c92cf2036367ac49a29f8c52ec510b
7
+ data.tar.gz: f32dd2bc3cf5d8f66e6f4566dd8be90a6cd0b1c6c2cf1d45fd5fef4566ef63fa3e1f23fd9e551c5f820f7b01ee9bd97990c4b844ceb6e4c56ee8f675f3a80a29
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.9
1
+ 0.3.10
@@ -44,6 +44,16 @@ module DbMemoize
44
44
  SQL
45
45
  end
46
46
 
47
+ ALL_COLUMNS = [
48
+ :val_string,
49
+ :val_integer,
50
+ :val_float,
51
+ :val_time,
52
+ :val_object,
53
+ :val_boolean,
54
+ :val_nil
55
+ ].freeze
56
+
47
57
  def self.fast_create(entity_table_name, entity_id, method_name, value)
48
58
  method_name = method_name.to_s
49
59
 
@@ -66,38 +76,17 @@ module DbMemoize
66
76
  raise "Unsupported value of type #{value.class.name}: #{value.inspect}"
67
77
  end
68
78
 
69
- value = JSON.generate(value) if column == :val_object
70
-
71
- # it looks like Simple::SQL somehow drops subsecond resolutions from
72
- # time objects. AR does not, though. So, for time values, we use the
73
- # ActiveRecord method; for everything else we use Simple::SQL (for
74
- # performance reasons: it is 10 times as fast.)
75
- if column != :val_time
76
- simple_sql_create_value column, entity_table_name: entity_table_name, entity_id: entity_id,
77
- method_name: method_name, value: value
78
- else
79
- ar_create_value column, entity_table_name: entity_table_name, entity_id: entity_id,
80
- method_name: method_name, value: value
79
+ # some types need special encoding
80
+ case column
81
+ when :val_object then value = _reformat_object(value)
82
+ when :val_time then value = _reformat_time(value)
81
83
  end
82
- end
83
84
 
84
- ALL_COLUMNS = [
85
- :val_string,
86
- :val_integer,
87
- :val_float,
88
- :val_time,
89
- :val_object,
90
- :val_boolean,
91
- :val_nil
92
- ].freeze
93
-
94
- def self.simple_sql_create_value(column, entity_table_name:, entity_id:, method_name:, value:)
95
85
  other_columns = ALL_COLUMNS - [column]
96
86
  default_updates = other_columns.map { |c| "#{c}=NULL" }
97
87
 
98
88
  sql = <<~SQL.freeze
99
- INSERT INTO #{table_name}
100
- (entity_table_name, entity_id, method_name, #{column}, created_at)
89
+ INSERT INTO #{table_name}(entity_table_name, entity_id, method_name, #{column}, created_at)
101
90
  VALUES($1,$2,$3,$4,NOW())
102
91
  ON CONFLICT (entity_id, entity_table_name, method_name)
103
92
  DO UPDATE
@@ -107,16 +96,20 @@ module DbMemoize
107
96
  SQL.ask sql, entity_table_name, entity_id, method_name, value
108
97
  end
109
98
 
110
- def self.ar_create_value(column, entity_table_name:, entity_id:, method_name:, value:)
111
- # [TODO] this code is not resolving conflicts on the unique index.
112
- data = {
113
- :entity_table_name => entity_table_name,
114
- :entity_id => entity_id,
115
- :method_name => method_name,
116
- column => value
117
- }
99
+ # Apparently the pg, and for that matter also simple-sql, drops subsecond
100
+ # resolution when passing in time objects. (Note that this seems not always
101
+ # to be the case, it probably depends on some encoder configuration within
102
+ # pg - which simple-sql is not touching, since this is a setting on a
103
+ # connection which might not be exclusive to simple-sql.)
104
+ #
105
+ # Instead we'll just pass along a string, postgresql will then convert it
106
+ # into a proper timestamp.
107
+ def self._reformat_time(t) # rubocop:disable Naming/UncommunicativeMethodParamName
108
+ format('%04d%02d-%02d %02d:%02d:%02d.%06d', t.year, t.mon, t.day, t.hour, t.min, t.sec, t.usec)
109
+ end
118
110
 
119
- create!(data)
111
+ def self._reformat_object(value)
112
+ JSON.generate(value)
120
113
  end
121
114
  end
122
115
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: db_memoize
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.9
4
+ version: 0.3.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - johannes-kostas goetzinger