pg_cache_key 0.1.4 → 0.1.5
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/README.md +5 -4
- data/Rakefile +5 -1
- data/lib/pg_cache_key/version.rb +1 -1
- data/lib/pg_cache_key.rb +25 -4
- data/pg_cache_key.gemspec +2 -0
- metadata +30 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e77a9f091922442dc6b19d2015d53e1e7bf93ece
|
4
|
+
data.tar.gz: 339813b6a21d0b8de74412de8b62567ad341ab3e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 930b14dc2c3545747b6209db0f378d403eb3a695b04de241ac6e934d5483636db09c6fb8bb109986bc918dd9c0782d8adc3a0e063848c63184662b5e93a4e448
|
7
|
+
data.tar.gz: 20bf20ebcda951fae3d0e5107bbd08de7e2a10c7be761daccbdf2f12c9ddaeeba91ecb16177bd2980658da9c60e6697a1358fe35842e19a6b65f7ba844535410
|
data/README.md
CHANGED
@@ -71,11 +71,12 @@ It works out of the box.
|
|
71
71
|
|
72
72
|
По идее работает само из коробки, но если будут траблы - пишите.
|
73
73
|
|
74
|
-
##
|
74
|
+
## Testing
|
75
|
+
Tested only query string for simple case. In your project you may test it on more specific query.
|
75
76
|
|
76
|
-
|
77
|
-
|
78
|
-
|
77
|
+
## Testing(рус)
|
78
|
+
Тестируется только строка запроса для самого простого случая + добавление метода в активрекорд релейшен.
|
79
|
+
Стабильность на сложных запросах специфических для вашего приложения можете добавить в свои тесты.
|
79
80
|
|
80
81
|
## Contributing
|
81
82
|
|
data/Rakefile
CHANGED
data/lib/pg_cache_key/version.rb
CHANGED
data/lib/pg_cache_key.rb
CHANGED
@@ -15,18 +15,39 @@ require "pg_cache_key/version"
|
|
15
15
|
# end
|
16
16
|
# end
|
17
17
|
|
18
|
-
|
18
|
+
module PgCacheKey
|
19
|
+
def cache_key_raw_sql( timestamp_column = :updated_at )
|
20
|
+
"SELECT md5(string_agg( t.ckc_#{timestamp_column}||t.ckc_id, '') ) as cache_key \
|
21
|
+
FROM (#{ select( [timestamp_column, :id].map{|ckc| "#{table_name}.#{ckc}::text as ckc_#{ckc}" } ).try(:to_sql) }) t"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# Actually this all depends on retrieve_cache_key(key) from active_support:
|
26
|
+
# def retrieve_cache_key(key)
|
27
|
+
# case
|
28
|
+
# when key.respond_to?(:cache_key) then key.cache_key
|
29
|
+
# when key.is_a?(Array) then key.map { |element| retrieve_cache_key(element) }.to_param
|
30
|
+
# when key.respond_to?(:to_a) then retrieve_cache_key(key.to_a)
|
31
|
+
# else key.to_param
|
32
|
+
# end.to_s
|
33
|
+
# end
|
34
|
+
# in rails 4 there is no cache_key in relations so if we deliver relation as key in rails 4 it will convert to array first
|
35
|
+
# in rails 5 there is cache_key, the method below is copy+paste from rails 5 except it doesn't use rails 5 collection_cache_key,
|
36
|
+
# and use it's own algorithm for cache_key
|
19
37
|
module ActiveRecord
|
20
38
|
# = Active Record \Relation
|
21
39
|
class Relation
|
40
|
+
include PgCacheKey
|
41
|
+
|
22
42
|
def cache_key(timestamp_column = :updated_at)
|
23
43
|
@cache_keys ||= {}
|
24
44
|
# Rem 1: why use connection.execute instead of doing collection.select because of an order. if you using some order on your scope
|
25
45
|
# then columns you using to order must appear in the GROUP BY clause or be used in an aggregate function or you will get an error
|
26
46
|
# Rem 2: we need to add select( cache_columns ) explicitly because if relation has includes it might transform columns to aliases
|
27
|
-
|
28
|
-
|
29
|
-
|
47
|
+
# and we must also select them as uniq-aliase so PG wouldn't be confused
|
48
|
+
# 'ckc' means cache key column :)
|
49
|
+
@cache_keys[timestamp_column] ||= connection.execute( cache_key_raw_sql(timestamp_column) )[0]['cache_key']
|
30
50
|
end
|
51
|
+
|
31
52
|
end
|
32
53
|
end
|
data/pg_cache_key.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pg_cache_key
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- alekseyl
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-09-
|
11
|
+
date: 2016-09-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -66,6 +66,34 @@ dependencies:
|
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: sqlite3
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
69
97
|
description: 'collection_cache_key replacement for system which uses PG as DB, uses
|
70
98
|
PG aggregation functions '
|
71
99
|
email:
|