trifle-stats 1.1.2 → 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/Gemfile.lock +1 -1
- data/README.md +1 -1
- data/bin/console +1 -0
- data/lib/trifle/stats/driver/postgres.rb +22 -25
- data/lib/trifle/stats/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: a42d81aa9cf531df2abc462167d9b173af444c2089f15f1d53354153b1fb18df
|
4
|
+
data.tar.gz: b5237b9c28ce0779ecdc3f129d26de062084490dd9b470b05ffb975a05ecc293
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d835304df2db49efd76728e0de0bb1ae827680a5ec1a5d4a071a9ac60ca4a045441b8afa5628ca6e38e7f07c010c2cd550bdb15b91409e89f9211242bed17527
|
7
|
+
data.tar.gz: '08e5fa3dceb15fd8927c2320efe73ab543801ac4bac99ff80a478ea344e03b0c6f1f78c7ec23a21c5ac18d22912f4a10774f5a6389e2ae5a428402776e057fc5'
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -12,7 +12,7 @@ Simple analytics backed by Redis, Postgres, MongoDB, Google Analytics, Segment,
|
|
12
12
|
|
13
13
|
## Documentation
|
14
14
|
|
15
|
-
You can find guides and documentation at https://trifle.io/
|
15
|
+
You can find guides and documentation at https://trifle.io/trifle-stats
|
16
16
|
|
17
17
|
## Installation
|
18
18
|
|
data/bin/console
CHANGED
@@ -20,15 +20,13 @@ module Trifle
|
|
20
20
|
keys.map do |key|
|
21
21
|
pkey = key.join(separator)
|
22
22
|
|
23
|
-
self.class.pack(hash: values)
|
24
|
-
_inc_one(key: pkey, name: k, value: c)
|
25
|
-
end
|
23
|
+
_inc_all(key: pkey, data: self.class.pack(hash: values))
|
26
24
|
end
|
27
25
|
end
|
28
26
|
|
29
|
-
def
|
30
|
-
|
31
|
-
|
27
|
+
def _inc_all(key:, data:)
|
28
|
+
query = "INSERT INTO trifle_stats(key, data) VALUES ('#{key}', '#{data.to_json}') ON CONFLICT (key) DO UPDATE SET data = " + # rubocop:disable Layout/LineLength
|
29
|
+
data.inject('to_jsonb(trifle_stats.data)') { |o, (k, v)| "jsonb_set(#{o}, '{#{k}}', (COALESCE(trifle_stats.data->>'#{k}', '0')::int + #{v})::text::jsonb)" } # rubocop:disable Layout/LineLength
|
32
30
|
|
33
31
|
client.exec(query)
|
34
32
|
end
|
@@ -37,37 +35,36 @@ module Trifle
|
|
37
35
|
keys.map do |key|
|
38
36
|
pkey = key.join(separator)
|
39
37
|
|
40
|
-
_set_all(key: pkey,
|
38
|
+
_set_all(key: pkey, data: self.class.pack(hash: values))
|
41
39
|
end
|
42
40
|
end
|
43
41
|
|
44
|
-
def _set_all(key:,
|
45
|
-
|
46
|
-
|
42
|
+
def _set_all(key:, data:)
|
43
|
+
query = "INSERT INTO trifle_stats(key, data) VALUES ('#{key}', '#{data.to_json}') ON CONFLICT (key) DO UPDATE SET data = " + # rubocop:disable Layout/LineLength
|
44
|
+
data.inject('to_jsonb(trifle_stats.data)') { |o, (k, v)| "jsonb_set(#{o}, '{#{k}}', (#{v})::text::jsonb)" } # rubocop:disable Layout/LineLength
|
47
45
|
|
48
46
|
client.exec(query)
|
49
47
|
end
|
50
48
|
|
51
49
|
def get(keys:)
|
52
|
-
keys.map
|
53
|
-
|
54
|
-
|
55
|
-
data = _get(key: pkey)
|
56
|
-
return {} if data.nil?
|
50
|
+
pkeys = keys.map { |key| key.join(separator) }
|
51
|
+
data = _get_all(keys: pkeys)
|
52
|
+
map = data.inject({}) { |o, d| o.merge(d['key'] => d['data']) }
|
57
53
|
|
58
|
-
|
59
|
-
end
|
54
|
+
pkeys.map { |pkey| self.class.unpack(hash: map[pkey]) || {} }
|
60
55
|
end
|
61
56
|
|
62
|
-
def
|
63
|
-
|
64
|
-
"SELECT * FROM #{table_name} WHERE key
|
65
|
-
).to_a
|
66
|
-
return nil if result.nil?
|
57
|
+
def _get_all(keys:)
|
58
|
+
results = client.exec_params(
|
59
|
+
"SELECT * FROM #{table_name} WHERE key IN ('#{keys.join("', '")}');"
|
60
|
+
).to_a
|
67
61
|
|
68
|
-
|
69
|
-
|
70
|
-
|
62
|
+
results.map do |r|
|
63
|
+
r['data'] = JSON.parse(r['data'])
|
64
|
+
r
|
65
|
+
rescue JSON::ParserError
|
66
|
+
r
|
67
|
+
end
|
71
68
|
end
|
72
69
|
end
|
73
70
|
end
|
data/lib/trifle/stats/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: trifle-stats
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jozef Vaclavik
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-07-
|
11
|
+
date: 2022-07-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|